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

2010-01-14 Thread Ken Resander
Many thanks Tadej!

event->button works fine. 

Here is trace info for left, right and simulated mid buttons:

 mousebuttonDOWN (x,y)=(10,14)state 0 btn=1
 mousebuttonUP (x,y)=(10,14)state 100 button=1
 
 mousebuttonDOWN (x,y)=(9,14)state 0 btn=3
 mousebuttonUP (x,y)=(9,14)state 400 button=3
 
 mousebuttonDOWN (x,y)=(9,14)state 0 btn=2
 mousebuttonUP (x,y)=(9,14)state 200 button=3
 mousebuttonUP (x,y)=(9,14)state 200 button=2

It shows state is not set on any ButtonDown event, ButtonUP works for left and 
right button but not for simulated mid button (should only be one UP event for 
button 2).

Should this behaviour be considered a bug?


--- On Thu, 14/1/10, Tadej Borovšak  wrote:

From: Tadej Borovšak 
Subject: Re: Not getting which mouse button is pressed on button-press-event
To: "Ken Resander" 
Cc: gtk-list@gnome.org
Date: Thursday, 14 January, 2010, 3:13 AM

Hello.

You can get the mouse button pressed by looking at event->button
field. 1 means left button, 2 middle button (which can usually be
emulated by pressing right and left button at once on 2-button mouse),
3 right button. I think 4-7 mean wheel movement (check API docs for
that, I'm not 100% sure).

Tadej

--
Tadej Borovšak
tadeboro.blogspot.com
tadeb...@gmail.com
tadej.borov...@gmail.com



  Get your preferred Email name!
Now you can @ymail.com and @rocketmail.com. 
http://mail.promotions.yahoo.com/newdomains/aa/___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


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

2010-01-13 Thread Ed James
Robert,
   You are right - I've been buried for days in X Windows code (not GTK+) and my
mindset was in the wrong place for this list.  My bad.

Ed James

On Wed, Jan 13, 2010 at 4:39 PM, Robert Pearce  
wrote:
> Hi Ed,
...
> But as I understand it, none of this is relevant to GTK, which just
> passes through what the back-end produces.
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


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

2010-01-13 Thread Robert Pearce
Hi Ed,

On Wed, 13 Jan 2010 15:11:21 -0500 you wrote:
> 
> Wasn't able to emulate middle button on my 2-button mouse (project for another
> day, perhaps). 

That's an X setting - EmulateMiddleButton or something of the like. If
it's set then X intercepts near-simultaneous left and right buttons and
substitutes a middle button.

> Can't verify 6,7, but perhaps it's time for me to buy a better
> mouse.  I wonder, though, if this might be useful with a joystick (left, 
> right).

Buttons 6 and 7 are generated by some track balls and mice with
excessive numbers of controls. You get some flexibility on what you map
them to, and it's possible to use them for scrolling instead of 4 and 5.

But as I understand it, none of this is relevant to GTK, which just
passes through what the back-end produces.


Rob
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


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

2010-01-13 Thread Ed James
Just tried it and verified most of the answer, via something I'm playing with;
UINT   ejEventManager::getButton  () {
   return currEvent.xbutton.button;
}

1 == Left mouse button
2 == Right mouse button
4 == scroll up
5 == scroll down

Wasn't able to emulate middle button on my 2-button mouse (project for another
day, perhaps).  Can't verify 6,7, but perhaps it's time for me to buy a better
mouse.  I wonder, though, if this might be useful with a joystick (left, right).

Ed James

On Wed, Jan 13, 2010 at 2:13 PM, Tadej Borovšak  wrote:
> Hello.
>
> You can get the mouse button pressed by looking at event->button
> field. 1 means left button, 2 middle button (which can usually be
> emulated by pressing right and left button at once on 2-button mouse),
> 3 right button. I think 4-7 mean wheel movement (check API docs for
> that, I'm not 100% sure).
>
> Tadej
>
> --
> Tadej Borovšak
> tadeboro.blogspot.com
> tadeb...@gmail.com
> tadej.borov...@gmail.com
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


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

2010-01-13 Thread Tadej Borovšak
Hello.

You can get the mouse button pressed by looking at event->button
field. 1 means left button, 2 middle button (which can usually be
emulated by pressing right and left button at once on 2-button mouse),
3 right button. I think 4-7 mean wheel movement (check API docs for
that, I'm not 100% sure).

Tadej

--
Tadej Borovšak
tadeboro.blogspot.com
tadeb...@gmail.com
tadej.borov...@gmail.com
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


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

2010-01-13 Thread Ken Resander
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. 
http://mail.promotions.yahoo.com/newdomains/aa/___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list