📄 gdkinput-x11.c
字号:
gint *axis_data, gdouble *axis_out, gdouble *x_out, gdouble *y_out){ GdkWindowImplX11 *impl; int i; int x_axis = 0; int y_axis = 0; double device_width, device_height; double x_offset, y_offset, x_scale, y_scale; impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *) input_window->window)->impl); for (i=0; i<gdkdev->info.num_axes; i++) { switch (gdkdev->info.axes[i].use) { case GDK_AXIS_X: x_axis = i; break; case GDK_AXIS_Y: y_axis = i; break; default: break; } } device_width = gdkdev->axes[x_axis].max_value - gdkdev->axes[x_axis].min_value; device_height = gdkdev->axes[y_axis].max_value - gdkdev->axes[y_axis].min_value; if (gdkdev->info.mode == GDK_MODE_SCREEN) { x_scale = gdk_screen_get_width (gdk_drawable_get_screen (input_window->window)) / device_width; y_scale = gdk_screen_get_height (gdk_drawable_get_screen (input_window->window)) / device_height; x_offset = - input_window->root_x; y_offset = - input_window->root_y; } else /* GDK_MODE_WINDOW */ { double x_resolution = gdkdev->axes[x_axis].resolution; double y_resolution = gdkdev->axes[y_axis].resolution; double device_aspect; /* * Some drivers incorrectly report the resolution of the device * as zero (in partiular linuxwacom < 0.5.3 with usb tablets). * This causes the device_aspect to become NaN and totally * breaks windowed mode. If this is the case, the best we can * do is to assume the resolution is non-zero is equal in both * directions (which is true for many devices). The absolute * value of the resolution doesn't matter since we only use the * ratio. */ if ((x_resolution == 0) || (y_resolution == 0)) { x_resolution = 1; y_resolution = 1; } device_aspect = (device_height*y_resolution) / (device_width*x_resolution); if (device_aspect * impl->width >= impl->height) { /* device taller than window */ x_scale = impl->width / device_width; y_scale = (x_scale * x_resolution) / y_resolution; x_offset = 0; y_offset = -(device_height * y_scale - impl->height)/2; } else { /* window taller than device */ y_scale = impl->height / device_height; x_scale = (y_scale * y_resolution) / x_resolution; y_offset = 0; x_offset = - (device_width * x_scale - impl->width)/2; } } for (i=0; i<gdkdev->info.num_axes; i++) { switch (gdkdev->info.axes[i].use) { case GDK_AXIS_X: axis_out[i] = x_offset + x_scale * axis_data[x_axis]; if (x_out) *x_out = axis_out[i]; break; case GDK_AXIS_Y: axis_out[i] = y_offset + y_scale * axis_data[y_axis]; if (y_out) *y_out = axis_out[i]; break; default: axis_out[i] = (gdkdev->info.axes[i].max * (axis_data[i] - gdkdev->axes[i].min_value) + gdkdev->info.axes[i].min * (gdkdev->axes[i].max_value - axis_data[i])) / (gdkdev->axes[i].max_value - gdkdev->axes[i].min_value); break; } }}/* combine the state of the core device and the device state * into one - for now we do this in a simple-minded manner - * we just take the keyboard portion of the core device and * the button portion (all of?) the device state. * Any button remapping should go on here. */static guintgdk_input_translate_state(guint state, guint device_state){ return device_state | (state & 0xFF);}gboolean_gdk_input_common_other_event (GdkEvent *event, XEvent *xevent, GdkInputWindow *input_window, GdkDevicePrivate *gdkdev){ if ((xevent->type == gdkdev->buttonpress_type) || (xevent->type == gdkdev->buttonrelease_type)) { XDeviceButtonEvent *xdbe = (XDeviceButtonEvent *)(xevent); if (xdbe->type == gdkdev->buttonpress_type) { event->button.type = GDK_BUTTON_PRESS; gdkdev->button_state |= 1 << xdbe->button; } else { event->button.type = GDK_BUTTON_RELEASE; gdkdev->button_state &= ~(1 << xdbe->button); } event->button.device = &gdkdev->info; event->button.window = input_window->window; event->button.time = xdbe->time; event->button.axes = g_new (gdouble, gdkdev->info.num_axes); gdk_input_translate_coordinates (gdkdev,input_window, xdbe->axis_data, event->button.axes, &event->button.x,&event->button.y); event->button.x_root = event->button.x + input_window->root_x; event->button.y_root = event->button.y + input_window->root_y; event->button.state = gdk_input_translate_state(xdbe->state,xdbe->device_state); event->button.button = xdbe->button; GDK_NOTE (EVENTS, g_print ("button %s:\t\twindow: %ld device: %ld x,y: %f %f button: %d\n", (event->button.type == GDK_BUTTON_PRESS) ? "press" : "release", xdbe->window, xdbe->deviceid, event->button.x, event->button.y, xdbe->button)); /* Update the timestamp of the latest user interaction, if the event has * a valid timestamp. */ if (gdk_event_get_time (event) != GDK_CURRENT_TIME) gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window), gdk_event_get_time (event)); return TRUE; } if ((xevent->type == gdkdev->keypress_type) || (xevent->type == gdkdev->keyrelease_type)) { XDeviceKeyEvent *xdke = (XDeviceKeyEvent *)(xevent); GDK_NOTE (EVENTS, g_print ("device key %s:\twindow: %ld device: %ld keycode: %d\n", (event->key.type == GDK_KEY_PRESS) ? "press" : "release", xdke->window, xdke->deviceid, xdke->keycode)); if (xdke->keycode < gdkdev->min_keycode || xdke->keycode >= gdkdev->min_keycode + gdkdev->info.num_keys) { g_warning ("Invalid device key code received"); return FALSE; } event->key.keyval = gdkdev->info.keys[xdke->keycode - gdkdev->min_keycode].keyval; if (event->key.keyval == 0) { GDK_NOTE (EVENTS, g_print ("\t\ttranslation - NONE\n")); return FALSE; } event->key.type = (xdke->type == gdkdev->keypress_type) ? GDK_KEY_PRESS : GDK_KEY_RELEASE; event->key.window = input_window->window; event->key.time = xdke->time; event->key.state = gdk_input_translate_state(xdke->state, xdke->device_state) | gdkdev->info.keys[xdke->keycode - gdkdev->min_keycode].modifiers; /* Add a string translation for the key event */ if ((event->key.keyval >= 0x20) && (event->key.keyval <= 0xFF)) { event->key.length = 1; event->key.string = g_new (gchar, 2); event->key.string[0] = (gchar)event->key.keyval; event->key.string[1] = 0; } else { event->key.length = 0; event->key.string = g_new0 (gchar, 1); } GDK_NOTE (EVENTS, g_print ("\t\ttranslation - keyval: %d modifiers: %#x\n", event->key.keyval, event->key.state)); /* Update the timestamp of the latest user interaction, if the event has * a valid timestamp. */ if (gdk_event_get_time (event) != GDK_CURRENT_TIME) gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window), gdk_event_get_time (event)); return TRUE; } if (xevent->type == gdkdev->motionnotify_type) { XDeviceMotionEvent *xdme = (XDeviceMotionEvent *)(xevent); event->motion.device = &gdkdev->info; event->motion.axes = g_new (gdouble, gdkdev->info.num_axes); gdk_input_translate_coordinates(gdkdev,input_window,xdme->axis_data, event->motion.axes, &event->motion.x,&event->motion.y); event->motion.x_root = event->motion.x + input_window->root_x; event->motion.y_root = event->motion.y + input_window->root_y; event->motion.type = GDK_MOTION_NOTIFY; event->motion.window = input_window->window; event->motion.time = xdme->time; event->motion.state = gdk_input_translate_state(xdme->state, xdme->device_state); event->motion.is_hint = xdme->is_hint; GDK_NOTE (EVENTS, g_print ("motion notify:\t\twindow: %ld device: %ld x,y: %f %f state %#4x hint: %s\n", xdme->window, xdme->deviceid, event->motion.x, event->motion.y, event->motion.state, (xdme->is_hint) ? "true" : "false")); /* Update the timestamp of the latest user interaction, if the event has * a valid timestamp. */ if (gdk_event_get_time (event) != GDK_CURRENT_TIME) gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window), gdk_event_get_time (event)); return TRUE; } if (xevent->type == gdkdev->proximityin_type || xevent->type == gdkdev->proximityout_type) { XProximityNotifyEvent *xpne = (XProximityNotifyEvent *)(xevent); event->proximity.device = &gdkdev->info; event->proximity.type = (xevent->type == gdkdev->proximityin_type)? GDK_PROXIMITY_IN:GDK_PROXIMITY_OUT; event->proximity.window = input_window->window; event->proximity.time = xpne->time; /* Update the timestamp of the latest user interaction, if the event has * a valid timestamp. */ if (gdk_event_get_time (event) != GDK_CURRENT_TIME) gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window), gdk_event_get_time (event)); return TRUE; } return FALSE; /* wasn't one of our event types */}gboolean_gdk_device_get_history (GdkDevice *device, GdkWindow *window, guint32 start, guint32 stop, GdkTimeCoord ***events, gint *n_events){ GdkTimeCoord **coords; XDeviceTimeCoord *device_coords; GdkInputWindow *input_window; GdkDevicePrivate *gdkdev; gint mode_return; gint axis_count_return; gint i; gdkdev = (GdkDevicePrivate *)device; input_window = _gdk_input_window_find (window); g_return_val_if_fail (input_window != NULL, FALSE); device_coords = XGetDeviceMotionEvents (GDK_WINDOW_XDISPLAY (window), gdkdev->xdevice, start, stop, n_events, &mode_return, &axis_count_return); if (device_coords) { coords = _gdk_device_allocate_history (device, *n_events); for (i=0; i<*n_events; i++) gdk_input_translate_coordinates (gdkdev, input_window, device_coords[i].data, coords[i]->axes, NULL, NULL); XFreeDeviceMotionEvents (device_coords); *events = coords; return TRUE; } else return FALSE;}void gdk_device_get_state (GdkDevice *device, GdkWindow *window, gdouble *axes, GdkModifierType *mask){ gint i; g_return_if_fail (device != NULL); g_return_if_fail (GDK_IS_WINDOW (window)); if (GDK_IS_CORE (device)) { gint x_int, y_int; gdk_window_get_pointer (window, &x_int, &y_int, mask); if (axes) { axes[0] = x_int; axes[1] = y_int; } } else { GdkDevicePrivate *gdkdev; GdkInputWindow *input_window; XDeviceState *state; XInputClass *input_class; if (mask) gdk_window_get_pointer (window, NULL, NULL, mask); gdkdev = (GdkDevicePrivate *)device; input_window = _gdk_input_window_find (window); g_return_if_fail (input_window != NULL); state = XQueryDeviceState (GDK_WINDOW_XDISPLAY (window), gdkdev->xdevice); input_class = state->data; for (i=0; i<state->num_classes; i++) { switch (input_class->class) { case ValuatorClass: if (axes) gdk_input_translate_coordinates (gdkdev, input_window, ((XValuatorState *)input_class)->valuators, axes, NULL, NULL); break; case ButtonClass: if (mask) { *mask &= 0xFF; if (((XButtonState *)input_class)->num_buttons > 0) *mask |= ((XButtonState *)input_class)->buttons[0] << 7; /* GDK_BUTTON1_MASK = 1 << 8, and button n is stored * in bit 1<<(n%8) in byte n/8. n = 1,2,... */ } break; } input_class = (XInputClass *)(((char *)input_class)+input_class->length); } XFreeDeviceState (state); }}#define __GDK_INPUT_X11_C__#include "gdkaliasdef.c"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -