RFC: calculate button modifiers for X peers

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

 



Hi,
the attached patch properly calculates the modifiers for mouse press
and release events.

Ok, to commit?

2007-05-22  Robert Schuster  <robertschuster@xxxxxxxx>

        * gnu/java/awt/peer/x/XEventQueue.java:
        (handleEvent): Calculate modifier value for mouse presse
        and release events.
        (buttonToModifier): New method.
        * gnu/java/awt/peer/x/KeyboardMapping.java:
        (mapModifiers): Added cases for alt gr and the meta key.

Regards
Robert
Index: gnu/java/awt/peer/x/KeyboardMapping.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/KeyboardMapping.java,v
retrieving revision 1.1
diff -u -r1.1 KeyboardMapping.java
--- gnu/java/awt/peer/x/KeyboardMapping.java	29 Jun 2006 15:15:56 -0000	1.1
+++ gnu/java/awt/peer/x/KeyboardMapping.java	22 May 2007 21:37:43 -0000
@@ -405,8 +405,12 @@
 
     if ((xMods & Input.SHIFT_MASK) != 0)
       mods |= KeyEvent.SHIFT_MASK | KeyEvent.SHIFT_DOWN_MASK;
+    if ((xMods & Input.META_MASK) != 0)
+      mods |= KeyEvent.META_MASK | KeyEvent.META_DOWN_MASK;
     if ((xMods & Input.ALT_MASK) != 0)
       mods |= KeyEvent.ALT_MASK | KeyEvent.ALT_DOWN_MASK;
+    if ((xMods & Input.MOD5_MASK) != 0)
+      mods |= KeyEvent.ALT_GRAPH_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK;
     if ((xMods & Input.CONTROL_MASK) != 0)
       mods |= KeyEvent.CTRL_MASK | KeyEvent.CTRL_DOWN_MASK;
 
Index: gnu/java/awt/peer/x/XEventPump.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/XEventPump.java,v
retrieving revision 1.5
diff -u -r1.5 XEventPump.java
--- gnu/java/awt/peer/x/XEventPump.java	22 May 2007 18:45:13 -0000	1.5
+++ gnu/java/awt/peer/x/XEventPump.java	22 May 2007 21:37:43 -0000
@@ -48,6 +48,8 @@
 import java.awt.event.PaintEvent;
 import java.util.HashMap;
 
+import gnu.java.awt.EventModifier;
+
 import gnu.x11.Display;
 import gnu.x11.event.ButtonPress;
 import gnu.x11.event.ButtonRelease;
@@ -162,10 +164,15 @@
       awtWindow = (Window) windows.get(key);
       // Create and post the mouse event.
       int button = bp.detail();
+
+      // AWT cannot handle more than 3 buttons and expects 0 instead.
+      if (button >= 3)
+        button = 0;
       drag = button;
 
       MouseEvent mp = new MouseEvent(awtWindow, MouseEvent.MOUSE_PRESSED,
-                                     System.currentTimeMillis(), 0,
+                                     System.currentTimeMillis(),
+                                     KeyboardMapping.mapModifiers(bp.state()) | buttonToModifier(button),
                                      bp.event_x(), bp.event_y(),
                                      1, false, button);
       Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mp);
@@ -174,11 +181,17 @@
       ButtonRelease br = (ButtonRelease) xEvent;
       key= new Integer(br.event_window_id);
       awtWindow = (Window) windows.get(key);
+
+      button = br.detail();
+      // AWT cannot handle more than 3 buttons and expects 0 instead.
+      if (button >= 3)
+        button = 0;
       drag = -1;
       MouseEvent mr = new MouseEvent(awtWindow, MouseEvent.MOUSE_RELEASED,
-                                     System.currentTimeMillis(), 0,
+                                     System.currentTimeMillis(),
+                                     KeyboardMapping.mapModifiers(br.state()) | buttonToModifier(button),
                                      br.event_x(), br.event_y(),
-                                     1, false, br.detail());
+                                     1, false, button);
       Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mr);
       break;
     case MotionNotify.CODE:
@@ -297,6 +310,23 @@
 
   }
 
+  /** Translates an X button identifier to the AWT's MouseEvent modifier
+   *  mask. As the AWT cannot handle more than 3 buttons those return
+   *  <code>0</code>.
+   */
+  static int buttonToModifier(int button)
+  {
+    switch (button)
+    {
+      case 1:
+        return MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON1_MASK;
+      case 2:
+        return MouseEvent.BUTTON2_DOWN_MASK | MouseEvent.BUTTON2_MASK;
+      case 3:
+        return MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON3_MASK;
+    }
 
-}
+    return 0;        
+  }
 
+}

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux