Re: Question about XInput in GTK



It turns out the problem is in the following line:

static gint
gdk_input_common_other_event (GdkEvent *event,
                              XEvent *xevent,
                              GdkInputWindow *input_window,
                              GdkDevicePrivate *gdkdev) {

.....
      gdk_input_translate_coordinates (gdkdev,input_window,
xdbe->axis_data, &event->button.x,
&event->button.y,
                                       &event->button.pressure,
                                       &event->button.xtilt,
                                       &event->button.ytilt);

    I dont what gdk_input_translate_coordinates does. Can someone tell
me? It just corrupt the X, Y coordiante I read from my gtk
input program.

Yick
Hong Kong,china





superylam netscape net wrote:

Hello World,

   I would like to ask a questiona about XInput in GTK.
I have a GTK program and in it, I have a drawing area that
response to the motion_notify event from my graphic tablet.
However, the coordinate I got from callback function is very
strange. For example, the screen is 800x600. However,
the range of X cooridnate I got report from the motion_notify
event runs from 0 to 912 instead of 0 to 799. I am sure the
driver is working perfectly as I tested it with "xinput -test"
and the cooridnates reported is correct!!!! Why?

   I have attached the source code.

Yick
Hong Kong, China



------------------------------------------------------------------------

#include <gtk/gtk.h>
#include <string.h>

#define DEVICE_NAME "GOGO_PEN"

void hello(GtkWidget *widget, gpointer data)
{
    g_print ("Hello World\n");
}

gint
delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    g_print ("delete event occurred\n");
    return(FALSE);
}

void
destroy(GtkWidget *widget, gpointer data)
{
    gtk_main_quit();
}

static gint
expose_event(GtkWidget *widget, GdkEventExpose *event) {
    g_print("expose_event\n");
    return FALSE;
}

static gint button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) {
    g_print("button pressed\n");
    return FALSE;
}

static gint
motion_notify_event(GtkWidget *widget, GdkEventMotion *event) {
    gdouble x, y;
    gdouble pressure;
    GdkRectangle update_rect;
    GdkModifierType state;

    if (event->is_hint) {
gdk_input_window_get_pointer(event->window, event->deviceid, &x, &y, &pressure, NULL, NULL, &state);
        g_print("motion_notify is_hint x%lfd y%lf device_id%d\n",
            x, y, event->deviceid);
    } else {
g_print("motion_notify is_not_hint x%lf y%lf device_id%d\n", event->x, event->y, event->deviceid);
    }

    gtk_widget_draw(widget, &update_rect);

    return TRUE;
}


static GdkDeviceInfo *find_device_info(char *name)
{
    GList *tmp_list = gdk_input_list_devices();
    GdkDeviceInfo *device, *found_device=NULL;

    while (tmp_list) {
    device=(GdkDeviceInfo *)tmp_list->data;
        if (strcmp(device->name, name)) {
        device->mode=GDK_MODE_DISABLED;
    } else {
        found_device=device;
        device->mode=GDK_MODE_WINDOW;
        }
        tmp_list = tmp_list->next;
    }
    return found_device;
}

void
input_dialog_destroy (GtkWidget *w, gpointer data)
{
  *((GtkWidget **)data) = NULL;
}

void
create_input_dialog ()
{
  static GtkWidget *inputd = NULL;

  if (!inputd)
    {
      inputd = gtk_input_dialog_new();

      gtk_signal_connect(GTK_OBJECT(inputd), "destroy",
          GTK_SIGNAL_FUNC(input_dialog_destroy), &inputd);
      gtk_signal_connect_object(
          GTK_OBJECT(GTK_INPUT_DIALOG (inputd)->close_button),
          "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide),
      GTK_OBJECT(inputd));

      gtk_widget_hide (GTK_INPUT_DIALOG (inputd)->save_button);

      gtk_widget_show (inputd);
    }
  else
    {
      if (!GTK_WIDGET_MAPPED (inputd))
        gtk_widget_show (inputd);
      else
        gdk_window_raise (inputd->window);
    }
}

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *drawing_area;
    GdkDeviceInfo *device_info;
gtk_init(&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_signal_connect (GTK_OBJECT (window), "delete_event",
            GTK_SIGNAL_FUNC (delete_event), NULL);
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
            GTK_SIGNAL_FUNC (destroy), NULL);

    drawing_area = gtk_drawing_area_new ();
    gtk_drawing_area_size(GTK_DRAWING_AREA(drawing_area), 200, 200);
    gtk_container_add (GTK_CONTAINER(window), drawing_area);
    gtk_signal_connect(GTK_OBJECT (drawing_area), "expose_event",
                  (GtkSignalFunc) expose_event, NULL);
    gtk_signal_connect(GTK_OBJECT (drawing_area), "motion_notify_event",
                      (GtkSignalFunc) motion_notify_event, NULL);
    gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event",
              (GtkSignalFunc) button_press_event, NULL);
    gtk_signal_connect(GTK_OBJECT (drawing_area), "button_release_event",
                  (GtkSignalFunc) button_press_event, (gpointer)1);

    gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK
                      | GDK_LEAVE_NOTIFY_MASK
                      | GDK_BUTTON_PRESS_MASK
                  | GDK_POINTER_MOTION_MASK
                      | GDK_POINTER_MOTION_HINT_MASK);

gtk_widget_set_extension_events(drawing_area, GDK_EXTENSION_EVENTS_CURSOR);

    gtk_widget_show(drawing_area);
    gtk_widget_show(window);

    create_input_dialog();

    /* Look for device... */
    device_info=find_device_info(DEVICE_NAME);

    if (!device_info) {
        g_error("unable to find device %s\n", DEVICE_NAME);
        return 1;
    }


    gtk_main ();
return(0);
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]