glut_input.c
来自「mesa-6.5-minigui源码」· C语言 代码 · 共 640 行 · 第 1/2 页
C
640 行
if (been_here) { return support; } been_here = True;#if !defined(_WIN32) version = XGetExtensionVersion(__glutDisplay, "XInputExtension"); /* Ugh. XInput extension API forces annoying cast of a pointer to a long so it can be compared with the NoSuchExtension value (#defined to 1). */ if (version == NULL || ((long) version) == NoSuchExtension) { support = 0; return support; } XFree(version); device_info = XListInputDevices(__glutDisplay, &num_dev); if (device_info) { for (i = 0; i < num_dev; i++) { /* XXX These are SGI names for these devices; unfortunately, no good standard exists for standard types of X input extension devices. */ device = &device_info[i]; any = (XAnyClassPtr) device->inputclassinfo; if (!__glutSpaceball && !strcmp(device->name, "spaceball")) { v = NULL; b = NULL; for (j = 0; j < device->num_classes; j++) {#if defined(__cplusplus) || defined(c_plusplus) switch (any->c_class) {#else switch (any->class) {#endif case ButtonClass: b = (XButtonInfoPtr) any; btns = b->num_buttons; break; case ValuatorClass: v = (XValuatorInfoPtr) any; /* Sanity check: at least 6 valuators? */ if (v->num_axes < NUM_SPACEBALL_AXIS) goto skip_device; a = (XAxisInfoPtr) ((char *) v + sizeof(XValuatorInfo)); for (k = 0; k < NUM_SPACEBALL_AXIS; k++, a++) { __glutSpaceballRange[k].min = a->min_value; __glutSpaceballRange[k].range = a->max_value - a->min_value; } break; } any = (XAnyClassPtr) ((char *) any + any->length); } if (v) { __glutSpaceball = XOpenDevice(__glutDisplay, device->id); if (__glutSpaceball) { __glutNumSpaceballButtons = btns; addDeviceEventParser(); } } } else if (!__glutDials && !strcmp(device->name, "dial+buttons")) { v = NULL; b = NULL; for (j = 0; j < device->num_classes; j++) {#if defined(__cplusplus) || defined(c_plusplus) switch (any->c_class) {#else switch (any->class) {#endif case ButtonClass: b = (XButtonInfoPtr) any; btns = b->num_buttons; break; case ValuatorClass: v = (XValuatorInfoPtr) any; /* Sanity check: at least 8 valuators? */ if (v->num_axes < NUM_DIALS_AXIS) goto skip_device; dials = v->num_axes; __glutDialsResolution = (int *) malloc(sizeof(int) * dials); a = (XAxisInfoPtr) ((char *) v + sizeof(XValuatorInfo)); for (k = 0; k < dials; k++, a++) { __glutDialsResolution[k] = a->resolution; } break; } any = (XAnyClassPtr) ((char *) any + any->length); } if (v) { __glutDials = XOpenDevice(__glutDisplay, device->id); if (__glutDials) { __glutNumButtonBoxButtons = btns; __glutNumDials = dials; addDeviceEventParser(); } } } else if (!__glutTablet && !strcmp(device->name, "tablet")) { v = NULL; b = NULL; for (j = 0; j < device->num_classes; j++) {#if defined(__cplusplus) || defined(c_plusplus) switch (any->c_class) {#else switch (any->class) {#endif case ButtonClass: b = (XButtonInfoPtr) any; btns = b->num_buttons; break; case ValuatorClass: v = (XValuatorInfoPtr) any; /* Sanity check: exactly 2 valuators? */ if (v->num_axes != NUM_TABLET_AXIS) goto skip_device; a = (XAxisInfoPtr) ((char *) v + sizeof(XValuatorInfo)); for (k = 0; k < NUM_TABLET_AXIS; k++, a++) { __glutTabletRange[k].min = a->min_value; __glutTabletRange[k].range = a->max_value - a->min_value; } break; } any = (XAnyClassPtr) ((char *) any + any->length); } if (v) { __glutTablet = XOpenDevice(__glutDisplay, device->id); if (__glutTablet) { __glutNumTabletButtons = btns; addDeviceEventParser(); } } } else if (!strcmp(device->name, "mouse")) { for (j = 0; j < device->num_classes; j++) {#if defined(__cplusplus) || defined(c_plusplus) if (any->c_class == ButtonClass) {#else if (any->class == ButtonClass) {#endif b = (XButtonInfoPtr) any; __glutNumMouseButtons = b->num_buttons; } any = (XAnyClassPtr) ((char *) any + any->length); } } skip_device:; } XFreeDeviceList(device_info); }#else /* _WIN32 */ __glutNumMouseButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);#endif /* !_WIN32 */ /* X Input extension might be supported, but only if there is a tablet, dials, or spaceball do we claim devices are supported. */ support = __glutTablet || __glutDials || __glutSpaceball; return support;}void__glutUpdateInputDeviceMask(GLUTwindow * window){#if !defined(_WIN32) /* 5 (dial and buttons) + 5 (tablet locator and buttons) + 5 (Spaceball buttons and axis) = 15 */ XEventClass eventList[15]; int rc, numEvents; rc = probeDevices(); if (rc) { numEvents = 0; if (__glutTablet) { if (window->tabletMotion) { DeviceMotionNotify(__glutTablet, __glutDeviceMotionNotify, eventList[numEvents]); numEvents++; } if (window->tabletButton) { DeviceButtonPress(__glutTablet, __glutDeviceButtonPress, eventList[numEvents]); numEvents++; DeviceButtonPressGrab(__glutTablet, __glutDeviceButtonPressGrab, eventList[numEvents]); numEvents++; DeviceButtonRelease(__glutTablet, __glutDeviceButtonRelease, eventList[numEvents]); numEvents++; } if (window->tabletMotion || window->tabletButton) { DeviceStateNotify(__glutTablet, __glutDeviceStateNotify, eventList[numEvents]); numEvents++; } } if (__glutDials) { if (window->dials) { DeviceMotionNotify(__glutDials, __glutDeviceMotionNotify, eventList[numEvents]); numEvents++; } if (window->buttonBox) { DeviceButtonPress(__glutDials, __glutDeviceButtonPress, eventList[numEvents]); numEvents++; DeviceButtonPressGrab(__glutDials, __glutDeviceButtonPressGrab, eventList[numEvents]); numEvents++; DeviceButtonRelease(__glutDials, __glutDeviceButtonRelease, eventList[numEvents]); numEvents++; } if (window->dials || window->buttonBox) { DeviceStateNotify(__glutDials, __glutDeviceStateNotify, eventList[numEvents]); numEvents++; } } if (__glutSpaceball) { if (window->spaceMotion || window->spaceRotate) { DeviceMotionNotify(__glutSpaceball, __glutDeviceMotionNotify, eventList[numEvents]); numEvents++; } if (window->spaceButton) { DeviceButtonPress(__glutSpaceball, __glutDeviceButtonPress, eventList[numEvents]); numEvents++; DeviceButtonPressGrab(__glutSpaceball, __glutDeviceButtonPressGrab, eventList[numEvents]); numEvents++; DeviceButtonRelease(__glutSpaceball, __glutDeviceButtonRelease, eventList[numEvents]); numEvents++; } if (window->spaceMotion || window->spaceRotate || window->spaceButton) { DeviceStateNotify(__glutSpaceball, __glutDeviceStateNotify, eventList[numEvents]); numEvents++; } }#if 0 if (window->children) { GLUTwindow *child = window->children; do { XChangeDeviceDontPropagateList(__glutDisplay, child->win, numEvents, eventList, AddToList); child = child->siblings; } while (child); }#endif XSelectExtensionEvent(__glutDisplay, window->win, eventList, numEvents); if (window->overlay) { XSelectExtensionEvent(__glutDisplay, window->overlay->win, eventList, numEvents); } } else { /* X Input extension not supported; no chance for exotic input devices. */ }#endif /* !_WIN32 */}/* CENTRY */int GLUTAPIENTRYglutDeviceGet(GLenum param){ probeDevices(); switch (param) { case GLUT_HAS_KEYBOARD: case GLUT_HAS_MOUSE: /* Assume window system always has mouse and keyboard. */ return 1; case GLUT_HAS_SPACEBALL: return __glutSpaceball != NULL; case GLUT_HAS_DIAL_AND_BUTTON_BOX: return __glutDials != NULL; case GLUT_HAS_TABLET: return __glutTablet != NULL; case GLUT_NUM_MOUSE_BUTTONS: return __glutNumMouseButtons; case GLUT_NUM_SPACEBALL_BUTTONS: return __glutNumSpaceballButtons; case GLUT_NUM_BUTTON_BOX_BUTTONS: return __glutNumButtonBoxButtons; case GLUT_NUM_DIALS: return __glutNumDials; case GLUT_NUM_TABLET_BUTTONS: return __glutNumTabletButtons; case GLUT_DEVICE_IGNORE_KEY_REPEAT: return __glutCurrentWindow->ignoreKeyRepeat;#ifndef _WIN32 case GLUT_DEVICE_KEY_REPEAT: { XKeyboardState state; XGetKeyboardControl(__glutDisplay, &state); return state.global_auto_repeat; } case GLUT_JOYSTICK_POLL_RATE: return 0;#else case GLUT_DEVICE_KEY_REPEAT: /* Win32 cannot globally disable key repeat. */ return GLUT_KEY_REPEAT_ON; case GLUT_JOYSTICK_POLL_RATE: return __glutCurrentWindow->joyPollInterval;#endif case GLUT_HAS_JOYSTICK: return __glutHasJoystick; case GLUT_JOYSTICK_BUTTONS: return __glutNumJoystickButtons; case GLUT_JOYSTICK_AXES: return __glutNumJoystickAxes; default: __glutWarning("invalid glutDeviceGet parameter: %d", param); return -1; }}/* ENDCENTRY */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?