FW: [gtk-list] Re: problem with grabbing pointer



On Linux, simply removing the GDK_POINTER_HINT_MASK from the
gdk_pointer_grab in testgtk.c fixed my problem for widgets (see promised
source code below).  On Win32, the event->x and event->y fields still seemed
wrong, but I was able to compensate by doing gdk_window_get_pointer to get
the correct x and y locations.

--Martin

#include <gtk/gtk.h>

static void box_released(GtkWidget *widget)
{
  printf("released\n");
  gtk_grab_remove(widget);
  gdk_pointer_ungrab(0);
}

static void box_motion(GtkWidget *widget, GdkEventMotion *event)
{
  int x,y;
  x=(int) event->x;
  y=(int) event->y;
  printf("x , y are %d %d\n",x,y%4096);
}

static void box_pressed(GtkWidget *widget, GdkEventButton *event)
{
 printf("pressed\n");
 if (event->type != GDK_BUTTON_PRESS) return;

 gtk_grab_add(widget);
 gdk_pointer_grab(widget->window, TRUE,
   GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK
   , NULL, NULL, 0);
}

int main(int argc, char *argv[]) {
   GtkWidget *window;
   GtkWidget *button;

   gtk_set_locale();

   gtk_init(&argc,&argv);
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

   gtk_container_border_width(GTK_CONTAINER(window),50);

   button = gtk_toggle_button_new_with_label("button");
   gtk_widget_set_events(button,GDK_BUTTON_MOTION_MASK |
      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
   gtk_signal_connect(GTK_OBJECT(button),"button_press_event",
      GTK_SIGNAL_FUNC(box_pressed),NULL);
   gtk_signal_connect(GTK_OBJECT(button),"button_release_event",
      GTK_SIGNAL_FUNC(box_released),NULL);
   gtk_signal_connect(GTK_OBJECT(button),"motion_notify_event",
      GTK_SIGNAL_FUNC(box_motion),NULL);
   gtk_container_add(GTK_CONTAINER(window),button);
   gtk_widget_show(button);
   gtk_widget_show(window);
   gtk_main();
   return 0;
}	

-----Original Message-----
From: Carlisle, Martin 
Sent: Wednesday, December 15, 1999 8:23 AM
To: 'gtk-list@redhat.com'
Subject: RE: [gtk-list] Re: problem with grabbing pointer


Thanks for your and Bernhard's comments.  I tried testgtk.c and it worked
just as you described.  I've made sure I'm using the exact same signals, and
calls to gtk_grab_add and gdk_pointer_grab with the same masks in the same
order, yet I'm not getting the same results.  I wonder if there is a
difference because the shapes are top level widgets, and I am trying to do
this on an event_box?

We're in the middle of finals here at the Air Force Academy, so I haven't
had lots of time to work on this.  I'll try to post a small sample program
after I strip down what I am doing.

--Martin



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