Re: [gtk-list] Window manager window placement and X modifiers/states



>Also much stranger question for Xlib wizards.  I'm monitoring certain keys
>and what modifiers they are pressed with.  Of course when KeyPressEvents
>come through, they have a state attached to them which roughly corresponds
>to what modifier was pressed with it.  I say "roughly" because normall the
>state without any modifier is 0, sometimes it's 16.  With Shift, sometimes
>it's 4, sometimes it's 20.  So I can't look for an absolute value, but I
>figure the modifiers seem to be unique modulo 16, (i.e. 16 is the same
>thing as 0 mod 16 and 20 is the same thing as 4 mod 16)
>
>is it reasonable to assume that most modifiers are going to be that way,
>or am I going to get a lot of spurious hits if I just look for the state %
>16?  I have no idea why the state is changing from program run to program
>run anyway...

>From /usr/include/gdk/gdktypes.h:

typedef enum
{
  GDK_SHIFT_MASK    = 1 << 0,
  GDK_LOCK_MASK	    = 1 << 1,
  GDK_CONTROL_MASK  = 1 << 2,
  GDK_MOD1_MASK	    = 1 << 3,
  GDK_MOD2_MASK	    = 1 << 4,
  GDK_MOD3_MASK	    = 1 << 5,
  GDK_MOD4_MASK	    = 1 << 6,
  GDK_MOD5_MASK	    = 1 << 7,
  GDK_BUTTON1_MASK  = 1 << 8,
  GDK_BUTTON2_MASK  = 1 << 9,
  GDK_BUTTON3_MASK  = 1 << 10,
  GDK_BUTTON4_MASK  = 1 << 11,
  GDK_BUTTON5_MASK  = 1 << 12,
  GDK_RELEASE_MASK  = 1 << 13,
  GDK_MODIFIER_MASK = 0x3fff
} GdkModifierType;

First of all, state is not unique for each modifier, but instead is
the bitwise-OR of all currently active modifiers. You need to look for
various state bits not by using an absolute value, but by using a
boolean logical expression:

	 if (ev.state & GDK_SHIFT_MASK) {
	    /* shift is pressed */
	 }

If you see 16 on one mouse press, and 0 on another, it means that for
one press, you had no modifiers pressed (state = 0), and on the other,
you had MOD2 active (1<<4). If you were just pressing Shift alone, you
would see a state value of 1 (1<<0), shift+ctrl = 5 (1<<0|1<<2) and so
on.

Hope this helps. More to the point, I hope I got this right instead of
pulling another embarrassing "pbd should be asleep at 01:10am instead
of answering technical email" stunt.

--p



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