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

📄 sec-addingxinputsupport.html

📁 gtk的教材和问答集
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Adding XInput support</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Scribble, A Simple Example Drawing Program"HREF="ch-scribble.html"><LINKREL="PREVIOUS"TITLE="The DrawingArea Widget, And Drawing"HREF="sec-thedrawingareawidget.html"><LINKREL="NEXT"TITLE="Tips For Writing GTK Applications"HREF="ch-tips.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-thedrawingareawidget.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 25. Scribble, A Simple Example Drawing Program</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="ch-tips.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-ADDINGXINPUTSUPPORT">25.4. Adding XInput support</A></H1><P>It is now possible to buy quite inexpensive input devices such as drawing tablets, which allow drawing with a much greaterease of artistic expression than does a mouse. The simplest wayto use such devices is simply as a replacement for the mouse,but that misses out many of the advantages of these devices,such as:</P><P></P><UL><LI><P> Pressure sensitivity</P></LI><LI><P> Tilt reporting</P></LI><LI><P> Sub-pixel positioning</P></LI><LI><P> Multiple inputs (for example, a stylus with a point and eraser)</P></LI></UL><P>For information about the XInput extension, see the <AHREF="http://www.gtk.org/~otaylor/xinput/howto/index.html"TARGET="_top">XInput HOWTO</A>.</P><P>If we examine the full definition of, for example, the GdkEventMotionstructure, we see that it has fields to support extended deviceinformation.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">struct _GdkEventMotion{  GdkEventType type;  GdkWindow *window;  guint32 time;  gdouble x;  gdouble y;  gdouble pressure;  gdouble xtilt;  gdouble ytilt;  guint state;  gint16 is_hint;  GdkInputSource source;  guint32 deviceid;};</PRE></TD></TR></TABLE><P><TTCLASS="LITERAL">pressure</TT> gives the pressure as a floating point number between0 and 1. <TTCLASS="LITERAL">xtilt</TT> and <TTCLASS="LITERAL">ytilt</TT> can take on values between -1 and 1, corresponding to the degree of tilt in each direction.<TTCLASS="LITERAL">source</TT> and <TTCLASS="LITERAL">deviceid</TT> specify the device for which theevent occurred in two different ways. <TTCLASS="LITERAL">source</TT> gives some simpleinformation about the type of device. It can take the enumerationvalues:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GDK_SOURCE_MOUSEGDK_SOURCE_PENGDK_SOURCE_ERASERGDK_SOURCE_CURSOR</PRE></TD></TR></TABLE><P><TTCLASS="LITERAL">deviceid</TT> specifies a unique numeric ID for the device. This canbe used to find out further information about the device using the<TTCLASS="LITERAL">gdk_input_list_devices()</TT> call (see below). The special value<TTCLASS="LITERAL">GDK_CORE_POINTER</TT> is used for the core pointer device. (Usuallythe mouse.)</P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN2906">25.4.1. Enabling extended device information</A></H2><P>To let GTK know about our interest in the extended device information,we merely have to add a single line to our program:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gtk_widget_set_extension_events (drawing_area, GDK_EXTENSION_EVENTS_CURSOR);</PRE></TD></TR></TABLE><P>By giving the value <TTCLASS="LITERAL">GDK_EXTENSION_EVENTS_CURSOR</TT> we say thatwe are interested in extension events, but only if we don't haveto draw our own cursor. See the section <AHREF="sec-addingxinputsupport.html#SEC-FURTHERSOPHISTICATIONS"> Further Sophistications </A> belowfor more information about drawing the cursor. We could also give the values <TTCLASS="LITERAL">GDK_EXTENSION_EVENTS_ALL</TT> if we were willing to draw our own cursor, or <TTCLASS="LITERAL">GDK_EXTENSION_EVENTS_NONE</TT> to revertback to the default condition.</P><P>This is not completely the end of the story however. By default,no extension devices are enabled. We need a mechanism to allowusers to enable and configure their extension devices. GTK providesthe InputDialog widget to automate this process. The followingprocedure manages an InputDialog widget. It creates the dialog ifit isn't present, and raises it to the top otherwise.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">voidinput_dialog_destroy (GtkWidget *w, gpointer data){  *((GtkWidget **)data) = NULL;}voidcreate_input_dialog (){  static GtkWidget *inputd = NULL;  if (!inputd)    {      inputd = gtk_input_dialog_new();      gtk_signal_connect (GTK_OBJECT(inputd), "destroy",			  (GtkSignalFunc)input_dialog_destroy, &#38;inputd);      gtk_signal_connect_object (GTK_OBJECT(GTK_INPUT_DIALOG(inputd)-&#62;close_button),				 "clicked",				 (GtkSignalFunc)gtk_widget_hide,				 GTK_OBJECT(inputd));      gtk_widget_hide ( GTK_INPUT_DIALOG(inputd)-&#62;save_button);      gtk_widget_show (inputd);    }  else    {      if (!GTK_WIDGET_MAPPED(inputd))	gtk_widget_show(inputd);      else	gdk_window_raise(inputd-&#62;window);    }}</PRE></TD></TR></TABLE><P>(You might want to take note of the way we handle this dialog.  Byconnecting to the "destroy" signal, we make sure that we don't keep apointer to dialog around after it is destroyed - that could lead to a

⌨️ 快捷键说明

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