⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdkinput-x11.c

📁 linux下电话本所依赖的一些图形库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* GDK - The GIMP Drawing Kit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS * file for a list of people on the GTK+ Team.  See the ChangeLog * files for a list of changes.  These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/.  */#include <config.h>#include "gdkinputprivate.h"#include "gdkinternals.h"#include "gdkx.h"#include "gdk.h"		/* For gdk_error_trap_push()/pop() */#include "gdkdisplay-x11.h"#include "gdkalias.h"#include <string.h>/* Forward declarations */static GdkDevicePrivate *gdk_input_device_new            (GdkDisplay       *display,							  XDeviceInfo      *device,							  gint              include_core);static void              gdk_input_translate_coordinates (GdkDevicePrivate *gdkdev,							  GdkInputWindow   *input_window,							  gint             *axis_data,							  gdouble          *axis_out,							  gdouble          *x_out,							  gdouble          *y_out);static guint             gdk_input_translate_state       (guint             state,							  guint             device_state);GdkDevicePrivate *_gdk_input_find_device (GdkDisplay *display,			guint32     id){  GList *tmp_list = GDK_DISPLAY_X11 (display)->input_devices;  GdkDevicePrivate *gdkdev;  while (tmp_list)    {      gdkdev = (GdkDevicePrivate *)(tmp_list->data);      if (gdkdev->deviceid == id)	return gdkdev;      tmp_list = tmp_list->next;    }  return NULL;}void_gdk_input_get_root_relative_geometry(Display *display, Window w, int *x_ret, int *y_ret,				      int *width_ret, int *height_ret){  Window root, parent, child;  Window *children;  guint nchildren;  gint x,y;  guint width, height;  guint border_widthc, depthc;     XQueryTree (display, w, &root, &parent, &children, &nchildren);  if (children)    XFree(children);    XGetGeometry (display, w, &root, &x, &y, &width, &height, &border_widthc, &depthc);  XTranslateCoordinates (display, w, root, 0, 0, &x, &y, &child);   if (x_ret)    *x_ret = x;  if (y_ret)    *y_ret = y;  if (width_ret)    *width_ret = width;  if (height_ret)    *height_ret = height;}static GdkDevicePrivate *gdk_input_device_new (GdkDisplay  *display,		      XDeviceInfo *device, 		      gint         include_core){  GdkDevicePrivate *gdkdev;  gchar *tmp_name;  XAnyClassPtr class;  gint i,j;  gdkdev = g_object_new (GDK_TYPE_DEVICE, NULL);  gdkdev->deviceid = device->id;  gdkdev->display = display;  if (device->name[0])    gdkdev->info.name = g_strdup (device->name); else   /* XFree86 3.2 gives an empty name to the default core devices,      (fixed in 3.2A) */   gdkdev->info.name = g_strdup ("pointer");  gdkdev->info.mode = GDK_MODE_DISABLED;  /* Try to figure out what kind of device this is by its name -     could invite a very, very, long list... Lowercase name     for comparison purposes */  tmp_name = g_ascii_strdown (gdkdev->info.name, -1);    if (!strcmp (tmp_name, "pointer"))    gdkdev->info.source = GDK_SOURCE_MOUSE;  else if (!strcmp (tmp_name, "wacom") ||	   !strcmp (tmp_name, "pen"))    gdkdev->info.source = GDK_SOURCE_PEN;  else if (!strcmp (tmp_name, "eraser"))    gdkdev->info.source = GDK_SOURCE_ERASER;  else if (!strcmp (tmp_name, "cursor"))    gdkdev->info.source = GDK_SOURCE_CURSOR;  else    gdkdev->info.source = GDK_SOURCE_PEN;  g_free(tmp_name);  gdkdev->xdevice = NULL;  /* step through the classes */  gdkdev->info.num_axes = 0;  gdkdev->info.num_keys = 0;  gdkdev->info.axes = NULL;  gdkdev->info.keys = NULL;  gdkdev->axes = 0;  gdkdev->info.has_cursor = 0;  gdkdev->needs_update = FALSE;  gdkdev->claimed = FALSE;  gdkdev->button_state = 0;  class = device->inputclassinfo;  for (i=0;i<device->num_classes;i++)     {      switch (class->class) {      case ButtonClass:	break;      case KeyClass:	{	  XKeyInfo *xki = (XKeyInfo *)class;	  /* Hack to catch XFree86 3.3.1 bug. Other devices better	   * not have exactly 25 keys... 	   */	  if ((xki->min_keycode == 8) && (xki->max_keycode == 32))	    {	      gdkdev->info.num_keys = 32;	      gdkdev->min_keycode = 1;	    }	  else	    {	      gdkdev->info.num_keys = xki->max_keycode - xki->min_keycode + 1;	      gdkdev->min_keycode = xki->min_keycode;	    }	  gdkdev->info.keys = g_new (GdkDeviceKey, gdkdev->info.num_keys);	  for (j=0; j<gdkdev->info.num_keys; j++)	    {	      gdkdev->info.keys[j].keyval = 0;	      gdkdev->info.keys[j].modifiers = 0;	    }	  break;	}      case ValuatorClass:	{	  XValuatorInfo *xvi = (XValuatorInfo *)class;	  gdkdev->info.num_axes = xvi->num_axes;	  gdkdev->axes = g_new (GdkAxisInfo, xvi->num_axes);	  gdkdev->info.axes = g_new0 (GdkDeviceAxis, xvi->num_axes);	  for (j=0;j<xvi->num_axes;j++)	    {	      gdkdev->axes[j].resolution = 		gdkdev->axes[j].xresolution = xvi->axes[j].resolution;	      gdkdev->axes[j].min_value =		gdkdev->axes[j].xmin_value = xvi->axes[j].min_value;	      gdkdev->axes[j].max_value =		gdkdev->axes[j].xmax_value = xvi->axes[j].max_value;	      gdkdev->info.axes[j].use = GDK_AXIS_IGNORE;	    }	  j=0;	  if (j<xvi->num_axes)	    gdk_device_set_axis_use (&gdkdev->info, j++, GDK_AXIS_X);	  if (j<xvi->num_axes)	    gdk_device_set_axis_use (&gdkdev->info, j++, GDK_AXIS_Y);	  if (j<xvi->num_axes)	    gdk_device_set_axis_use (&gdkdev->info, j++, GDK_AXIS_PRESSURE);	  if (j<xvi->num_axes)	    gdk_device_set_axis_use (&gdkdev->info, j++, GDK_AXIS_XTILT);	  if (j<xvi->num_axes)	    gdk_device_set_axis_use (&gdkdev->info, j++, GDK_AXIS_YTILT);	  if (j<xvi->num_axes)	    gdk_device_set_axis_use (&gdkdev->info, j++, GDK_AXIS_WHEEL);		       	  break;	}      }      class = (XAnyClassPtr)(((char *)class) + class->length);    }  /* return NULL if no axes */  if (!gdkdev->info.num_axes || !gdkdev->axes ||      (!include_core && device->use == IsXPointer))    goto error;  if (device->use != IsXPointer)    {      gdk_error_trap_push ();      gdkdev->xdevice = XOpenDevice (GDK_DISPLAY_XDISPLAY (display),				     gdkdev->deviceid);      /* return NULL if device is not ready */      if (gdk_error_trap_pop ())	goto error;    }  gdkdev->buttonpress_type = 0;  gdkdev->buttonrelease_type = 0;  gdkdev->keypress_type = 0;  gdkdev->keyrelease_type = 0;  gdkdev->motionnotify_type = 0;  gdkdev->proximityin_type = 0;  gdkdev->proximityout_type = 0;  gdkdev->changenotify_type = 0;  return gdkdev; error:  g_free (gdkdev->info.name);  if (gdkdev->axes)    g_free (gdkdev->axes);  if (gdkdev->info.keys)    g_free (gdkdev->info.keys);  if (gdkdev->info.axes)    g_free (gdkdev->info.axes);  g_object_unref (gdkdev);    return NULL;}void_gdk_input_common_find_events(GdkWindow *window,			      GdkDevicePrivate *gdkdev,			      gint mask,			      XEventClass *classes,			      int *num_classes){  gint i;  XEventClass class;    i = 0;  if (mask & GDK_BUTTON_PRESS_MASK)    {      DeviceButtonPress (gdkdev->xdevice, gdkdev->buttonpress_type,			     class);      if (class != 0)	  classes[i++] = class;      DeviceButtonPressGrab (gdkdev->xdevice, 0, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_BUTTON_RELEASE_MASK)    {      DeviceButtonRelease (gdkdev->xdevice, gdkdev->buttonrelease_type,			   class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_POINTER_MOTION_MASK)    {      DeviceMotionNotify  (gdkdev->xdevice, gdkdev->motionnotify_type, class);      if (class != 0)	  classes[i++] = class;    }  else    if (mask & (GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK |		GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_MOTION_MASK |		GDK_POINTER_MOTION_HINT_MASK))      {	/* Make sure gdkdev->motionnotify_type is set */	DeviceMotionNotify  (gdkdev->xdevice, gdkdev->motionnotify_type, class);      }  if (mask & GDK_BUTTON1_MOTION_MASK)    {      DeviceButton1Motion  (gdkdev->xdevice, 0, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_BUTTON2_MOTION_MASK)    {      DeviceButton2Motion  (gdkdev->xdevice, 0, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_BUTTON3_MOTION_MASK)    {      DeviceButton3Motion  (gdkdev->xdevice, 0, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_BUTTON_MOTION_MASK)    {      DeviceButtonMotion  (gdkdev->xdevice, 0, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_POINTER_MOTION_HINT_MASK)    {      /* We'll get into trouble if the macros change, but at least we'll	 know about it, and we avoid warnings now */      DevicePointerMotionHint (gdkdev->xdevice, 0, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_KEY_PRESS_MASK)    {      DeviceKeyPress (gdkdev->xdevice, gdkdev->keypress_type, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_KEY_RELEASE_MASK)    {      DeviceKeyRelease (gdkdev->xdevice, gdkdev->keyrelease_type, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_PROXIMITY_IN_MASK)    {      ProximityIn   (gdkdev->xdevice, gdkdev->proximityin_type, class);      if (class != 0)	  classes[i++] = class;    }  if (mask & GDK_PROXIMITY_OUT_MASK)    {      ProximityOut  (gdkdev->xdevice, gdkdev->proximityout_type, class);      if (class != 0)	  classes[i++] = class;    }  *num_classes = i;}void_gdk_input_common_select_events(GdkWindow *window,				GdkDevicePrivate *gdkdev){  XEventClass classes[GDK_MAX_DEVICE_CLASSES];  gint num_classes;  if (gdkdev->info.mode == GDK_MODE_DISABLED)    _gdk_input_common_find_events(window, gdkdev, 0, classes, &num_classes);  else    _gdk_input_common_find_events(window, gdkdev, 				  ((GdkWindowObject *)window)->extension_events,				  classes, &num_classes);    XSelectExtensionEvent (GDK_WINDOW_XDISPLAY (window),			 GDK_WINDOW_XWINDOW (window),			 classes, num_classes);}gint _gdk_input_common_init (GdkDisplay *display,			gint        include_core){  XDeviceInfo   *devices;  int num_devices, loop;  int ignore, event_base;  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);  /* Init XInput extension */  display_x11->input_devices = NULL;  if (XQueryExtension (display_x11->xdisplay, "XInputExtension",		       &ignore, &event_base, &ignore))    {      gdk_x11_register_standard_event_type (display,					    event_base, 15 /* Number of events */);      devices = XListInputDevices(display_x11->xdisplay, &num_devices);        for(loop=0; loop<num_devices; loop++)	{	  GdkDevicePrivate *gdkdev = gdk_input_device_new(display,							  &devices[loop],							  include_core);	  if (gdkdev)	    display_x11->input_devices = g_list_append(display_x11->input_devices, gdkdev);	}      XFreeDeviceList(devices);    }  display_x11->input_devices = g_list_append (display_x11->input_devices, display->core_pointer);  return TRUE;}static voidgdk_input_translate_coordinates (GdkDevicePrivate *gdkdev,				 GdkInputWindow   *input_window,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -