Not getting which mouse button is pressed on button-press-event

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

 



The state member in GdkEventButton for the button-press/release events contains flag bits that specify which mouse button is operated and also any keyboard shift/ctrl/alt modifier bits. I have tried button-press-event on several widget types, but in all cases the modifier bit GDK_BUTTON1_MASK or GDK_BUTTON2_MASK is not set on button-press. It is however set in the button-release-event.

If a mouse button is held down while pressing keys the state in GdkEventKey shows the correct GDK_BUTTON1_MASK or GDK_BUTTON2_MASK.

I need to know the mouse button pressed on button-press.

The program below shows this for a top window widget.


static gboolean buttonpresscallback ( GtkWidget * w,
                                      GdkEventButton * event,
                                      char * data )
   {
  printf ( " mousebuttonDOWN (x,y)=(%d,%d)state %x\n" ,
          (int)event->x , (int)event->y , event->state ) ;
   return false;
   }


static gboolean buttonreleasecallback ( GtkWidget * w,
                                        GdkEventButton * event,
                                        char * data )
   {
  printf ( " mousebuttonUP (x,y)=(%d,%d)state %x\n" ,
          (int)event->x , (int)event->y , event->state ) ;
   return false;
   }


static gboolean keypresscallback ( GtkWidget * w,
                                   GdkEventKey *event,
                                   char * data )
   {
  printf ( " key PRESS val=%x state=%x\n" , event->keyval , event->state ) ;
   return false;
   }


static gboolean keyreleasecallback ( GtkWidget *eventbox,
                                     GdkEventKey *event,
                                     char * data )
   {
  printf ( " key RELEASE val=%x state=%x\n" , event->keyval , event->state ) ;
   return false;
   }



int main ( int argc , char * argv[] )
   {
   gtk_init(&argc, &argv);

   GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
   gtk_window_set_default_size(GTK_WINDOW(window), 250, 180);
   gtk_window_set_title(GTK_WINDOW(window), "Testing");

   gtk_widget_add_events (window , GDK_BUTTON_PRESS_MASK );
   g_signal_connect (window, "button-press-event",
                     G_CALLBACK (buttonpresscallback), NULL ) ;

   gtk_widget_add_events (window, GDK_BUTTON_RELEASE_MASK );
   g_signal_connect (window, "button-release-event",
                     G_CALLBACK (buttonreleasecallback), NULL ) ;

   gtk_widget_add_events (window, GDK_KEY_PRESS_MASK );
   g_signal_connect ( window, "key-press-event",
                      G_CALLBACK (keypresscallback), NULL ) ;

   gtk_widget_add_events (window, GDK_KEY_RELEASE_MASK );
   g_signal_connect ( window, "key-release-event",
                      G_CALLBACK (keyreleasecallback), NULL ) ;

   g_signal_connect(window, "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

   gtk_widget_show_all(window);
   gtk_main();

   return 0;
   }


Am I doing something wrong?

I have a two-button mouse and observed that the right-mouse corresponds to GDK_BUTTON3_MASK, not GDK_BUTTON2_MASK that I expected. However, when I mistakenly pressed left and right button together I received the result GDK_BUTTON2 on button-release. Is this the way it is? What about bit mask and button correspondence for a 5-button mouse (if such animal exists in the real world)?



Get your preferred Email name!
Now you can @ymail.com and @rocketmail.com.
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux