summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2008-05-19 14:16:18 +0000
committerMario Torre <neugens@limasoftware.net>2008-05-19 14:16:18 +0000
commitb9cbde9915eda70a27b105c3117ecaee2b06cd3f (patch)
tree39f5d8c86691cf0acc5c6af71fc3ed77a69de27d /gnu
parent3e1edfd30fc31ee014dbc4dd35f972072d9c0650 (diff)
downloadclasspath-b9cbde9915eda70a27b105c3117ecaee2b06cd3f.tar.gz
2008-05-19 Mario Torre <neugens@aicas.com>
* gnu/java/awt/peer/x/XEventPump.java (handleExpose): new method. (handleDestroyNotify): likewise. (handleClientMessage): likewise. (handleButtonRelease): likewise. (handleMotionNotify): likewise. (handleKeyEvent): likewise. (handleButtonPress): likewise. (handleEvent): refactored to use new methods instead of a big switch block. Fixed resizing of windows. * gnu/java/awt/peer/x/XWindowPeer.java (standardSelect): update list of flags for X11 events handling. (callback): removed now unused flag.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/java/awt/peer/x/XEventPump.java312
-rw-r--r--gnu/java/awt/peer/x/XWindowPeer.java28
2 files changed, 188 insertions, 152 deletions
diff --git a/gnu/java/awt/peer/x/XEventPump.java b/gnu/java/awt/peer/x/XEventPump.java
index 214aefba0..9db36b51d 100644
--- a/gnu/java/awt/peer/x/XEventPump.java
+++ b/gnu/java/awt/peer/x/XEventPump.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package gnu.java.awt.peer.x;
+import java.awt.AWTEvent;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
@@ -50,6 +51,8 @@ import java.awt.event.PaintEvent;
import java.awt.event.WindowEvent;
import java.util.HashMap;
+import gnu.java.awt.ComponentReshapeEvent;
+import gnu.x11.Atom;
import gnu.x11.Display;
import gnu.x11.event.ButtonPress;
import gnu.x11.event.ButtonRelease;
@@ -62,6 +65,8 @@ import gnu.x11.event.Input;
import gnu.x11.event.KeyPress;
import gnu.x11.event.KeyRelease;
import gnu.x11.event.MotionNotify;
+import gnu.x11.event.PropertyNotify;
+import gnu.x11.event.ResizeRequest;
import gnu.x11.event.UnmapNotify;
/**
@@ -152,158 +157,201 @@ public class XEventPump
windows.remove(new Integer(xWindow.id));
}
- private void handleEvent(Event xEvent)
+ private void handleButtonPress(ButtonPress event)
+ {
+ Integer key = new Integer(event.getEventWindowID());
+ Window awtWindow = (Window) windows.get(key);
+
+ // Create and post the mouse event.
+ int button = event.detail();
+
+ // AWT cannot handle more than 3 buttons and expects 0 instead.
+ if (button >= gnu.x11.Input.BUTTON3)
+ button = 0;
+ drag = button;
+
+ MouseEvent mp = new MouseEvent(awtWindow, MouseEvent.MOUSE_PRESSED,
+ System.currentTimeMillis(),
+ KeyboardMapping.mapModifiers(event.getState())
+ | buttonToModifier(button),
+ event.getEventX(), event.getEventY(),
+ 1, false, button);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mp);
+ }
+
+ private void handleButtonRelease(ButtonRelease event)
+ {
+ Integer key = new Integer(event.getEventWindowID());
+ Window awtWindow = (Window) windows.get(key);
+
+ int button = event.detail();
+
+ // AWT cannot handle more than 3 buttons and expects 0 instead.
+ if (button >= gnu.x11.Input.BUTTON3)
+ button = 0;
+ drag = -1;
+
+ MouseEvent mr = new MouseEvent(awtWindow, MouseEvent.MOUSE_RELEASED,
+ System.currentTimeMillis(),
+ KeyboardMapping.mapModifiers(event.getState())
+ | buttonToModifier(button),
+ event.getEventX(), event.getEventY(),
+ 1, false, button);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mr);
+ }
+
+ private void handleMotionNotify(MotionNotify event)
+ {
+ Integer key = new Integer(event.getEventWindowID());
+ Window awtWindow = (Window) windows.get(key);
+
+ int button = event.detail();
+
+ // AWT cannot handle more than 3 buttons and expects 0 instead.
+ if (button >= gnu.x11.Input.BUTTON3)
+ button = 0;
+
+ MouseEvent mm = null;
+ if (drag == -1)
+ {
+ mm = new MouseEvent(awtWindow, MouseEvent.MOUSE_MOVED,
+ System.currentTimeMillis(),
+ KeyboardMapping.mapModifiers(event.getState())
+ | buttonToModifier(button),
+ event.getEventX(), event.getEventY(),
+ 1, false);
+
+ }
+ else
+ {
+ mm = new MouseEvent(awtWindow, MouseEvent.MOUSE_DRAGGED,
+ System.currentTimeMillis(),
+ KeyboardMapping.mapModifiers(event.getState())
+ | buttonToModifier(drag),
+ event.getEventX(), event.getEventY(),
+ 1, false);
+ }
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mm);
+ }
+
+ // FIME: refactor and make faster, maybe caching the event and handle
+ // and/or check timing (timing is generated for PropertyChange)?
+ private void handleExpose(Expose event)
+ {
+ Integer key = new Integer(event.window_id);
+ Window awtWindow = (Window) windows.get(key);
+
+ if (XToolkit.DEBUG)
+ System.err.println("expose request for window id: " + key);
+
+ Rectangle r = new Rectangle(event.x(), event.y(), event.width(),
+ event.height());
+ // We need to clear the background of the exposed rectangle.
+ assert awtWindow != null : "awtWindow == null for window ID: " + key;
+
+ Graphics g = awtWindow.getGraphics();
+ g.clearRect(r.x, r.y, r.width, r.height);
+ g.dispose();
+
+ XWindowPeer xwindow = (XWindowPeer) awtWindow.getPeer();
+ Insets i = xwindow.insets();
+ if (event.width() != awtWindow.getWidth() - i.left - i.right
+ || event.height() != awtWindow.getHeight() - i.top - i.bottom)
+ {
+ int w = event.width();
+ int h = event.height();
+ int x = xwindow.xwindow.x;
+ int y = xwindow.xwindow.y;
+
+ if (XToolkit.DEBUG)
+ System.err.println("Setting size on AWT window: " + w
+ + ", " + h + ", " + awtWindow.getWidth()
+ + ", " + awtWindow.getHeight());
+
+ // new width and height
+ xwindow.xwindow.width = w;
+ xwindow.xwindow.height = h;
+
+ // reshape the window
+ ComponentReshapeEvent cre =
+ new ComponentReshapeEvent(awtWindow, x, y, w, h);
+ awtWindow.dispatchEvent(cre);
+ }
+
+ ComponentEvent ce =
+ new ComponentEvent(awtWindow, ComponentEvent.COMPONENT_RESIZED);
+ awtWindow.dispatchEvent(ce);
+
+ PaintEvent pev = new PaintEvent(awtWindow, PaintEvent.UPDATE, r);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(pev);
+ }
+
+ private void handleDestroyNotify(DestroyNotify destroyNotify)
+ {
+ if (XToolkit.DEBUG)
+ System.err.println("DestroyNotify event: " + destroyNotify);
+
+ Integer key = new Integer(destroyNotify.event_window_id);
+ Window awtWindow = (Window) windows.get(key);
+
+ AWTEvent event = new WindowEvent(awtWindow, WindowEvent.WINDOW_CLOSED);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
+ }
+
+ private void handleClientMessage(ClientMessage clientMessage)
{
- Integer key = null;
- Window awtWindow = null;
- WindowEvent event = null;
+ if (XToolkit.DEBUG)
+ System.err.println("ClientMessage event: " + clientMessage);
+ if (clientMessage.delete_window())
+ {
+ if (XToolkit.DEBUG)
+ System.err.println("ClientMessage is a delete_window event");
+
+ Integer key = new Integer(clientMessage.window_id);
+ Window awtWindow = (Window) windows.get(key);
+
+ AWTEvent event = new WindowEvent(awtWindow, WindowEvent.WINDOW_CLOSING);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
+ }
+ }
+
+ private void handleEvent(Event xEvent)
+ {
if (XToolkit.DEBUG)
System.err.println("fetched event: " + xEvent);
+
switch (xEvent.code() & 0x7f)
{
case ButtonPress.CODE:
- ButtonPress bp = (ButtonPress) xEvent;
- key= new Integer(bp.event_window_id);
- 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 >= gnu.x11.Input.BUTTON3)
- button = 0;
- drag = button;
-
- MouseEvent mp = new MouseEvent(awtWindow, MouseEvent.MOUSE_PRESSED,
- System.currentTimeMillis(),
- KeyboardMapping.mapModifiers(bp.state()) | buttonToModifier(button),
- bp.event_x(), bp.event_y(),
- 1, false, button);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mp);
+ this.handleButtonPress((ButtonPress) xEvent);
break;
case ButtonRelease.CODE:
- 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 >= gnu.x11.Input.BUTTON3)
- button = 0;
- drag = -1;
- MouseEvent mr = new MouseEvent(awtWindow, MouseEvent.MOUSE_RELEASED,
- System.currentTimeMillis(),
- KeyboardMapping.mapModifiers(br.state()) | buttonToModifier(button),
- br.event_x(), br.event_y(),
- 1, false, button);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mr);
+ this.handleButtonRelease((ButtonRelease) xEvent);
break;
case MotionNotify.CODE:
- MotionNotify mn = (MotionNotify) xEvent;
- key= new Integer(mn.event_window_id);
- awtWindow = (Window) windows.get(key);
-
- button = mn.detail();
- // AWT cannot handle more than 3 buttons and expects 0 instead.
- if (button >= gnu.x11.Input.BUTTON3)
- button = 0;
-
- MouseEvent mm;
- if (drag == -1)
- {
- mm = new MouseEvent(awtWindow, MouseEvent.MOUSE_MOVED,
- System.currentTimeMillis(),
- KeyboardMapping.mapModifiers(mn.state()) | buttonToModifier(button),
- mn.event_x(), mn.event_y(),
- 1, false);
-
- }
- else
- {
- mm = new MouseEvent(awtWindow, MouseEvent.MOUSE_DRAGGED,
- System.currentTimeMillis(),
- KeyboardMapping.mapModifiers(mn.state()) | buttonToModifier(drag),
- mn.event_x(), mn.event_y(),
- 1, false);
- }
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(mm);
- break;
- case ConfigureNotify.CODE:
- key= new Integer(((ConfigureNotify) xEvent).event_window_id);
- awtWindow = (Window) windows.get(key);
- ConfigureNotify c = (ConfigureNotify) xEvent;
- if (XToolkit.DEBUG)
- System.err.println("resize request for window id: " + key);
-
- // Detect and report size changes.
- XWindowPeer xwindow = (XWindowPeer) awtWindow.getPeer();
- Insets i = xwindow.insets();
- if (c.width() != awtWindow.getWidth() - i.left - i.right
- || c.height() != awtWindow.getHeight() - i.top - i.bottom)
- {
- if (XToolkit.DEBUG)
- System.err.println("Setting size on AWT window: " + c.width()
- + ", " + c.height() + ", " + awtWindow.getWidth()
- + ", " + awtWindow.getHeight());
- xwindow.callback = true;
- xwindow.xwindow.width = c.width();
- xwindow.xwindow.height = c.height();
- awtWindow.setSize(c.width() + i.left + i.right,
- c.height() + i.top + i.bottom);
- xwindow.callback = false;
- }
+ this.handleMotionNotify((MotionNotify) xEvent);
break;
case Expose.CODE:
- key= new Integer(((Expose) xEvent).window_id);
- awtWindow = (Window) windows.get(key);
- Expose exp = (Expose) xEvent;
- if (XToolkit.DEBUG)
- System.err.println("expose request for window id: " + key);
- Rectangle r = new Rectangle(exp.x(), exp.y(), exp.width(),
- exp.height());
- //System.err.println("expose paint: " + r);
- // We need to clear the background of the exposed rectangle.
- assert awtWindow != null : "awtWindow == null for window ID: " + key;
- Graphics g = awtWindow.getGraphics();
- g.clearRect(r.x, r.y, r.width, r.height);
- g.dispose();
- PaintEvent pev = new PaintEvent(awtWindow, PaintEvent.PAINT, r);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(pev);
+ this.handleExpose((Expose) xEvent);
break;
case KeyPress.CODE:
case KeyRelease.CODE:
- key = new Integer(((Input) xEvent).event_window_id);
- awtWindow = (Window) windows.get(key);
+ Integer key = new Integer(((Input) xEvent).getEventWindowID());
+ Window awtWindow = (Window) windows.get(key);
handleKeyEvent(xEvent, awtWindow);
break;
- case UnmapNotify.CODE:
- if (XToolkit.DEBUG)
- System.err.println("UnmapNotify event: " + xEvent);
- key = new Integer(((UnmapNotify) xEvent).event_window_id);
- awtWindow = (Window) windows.get(key);
- event = new WindowEvent(awtWindow, WindowEvent.WINDOW_CLOSING);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
- break;
case DestroyNotify.CODE:
- if (XToolkit.DEBUG)
- System.err.println("DestroyNotify event: " + xEvent);
- key = new Integer(((DestroyNotify) xEvent).event_window_id);
- awtWindow = (Window) windows.get(key);
- event = new WindowEvent(awtWindow, WindowEvent.WINDOW_CLOSED);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
+ this.handleDestroyNotify((DestroyNotify) xEvent);
break;
case ClientMessage.CODE:
- if (XToolkit.DEBUG)
- System.err.println("ClientMessage event: " + xEvent);
- if (((ClientMessage) xEvent).delete_window())
- {
- if (XToolkit.DEBUG)
- System.err.println("ClientMessage is a delete_window event");
- key = new Integer(((ClientMessage) xEvent).window_id);
- awtWindow = (Window) windows.get(key);
- event = new WindowEvent(awtWindow, WindowEvent.WINDOW_CLOSING);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
- }
+ this.handleClientMessage((ClientMessage) xEvent);
+ break;
+ case PropertyNotify.CODE:
+ key = new Integer (((PropertyNotify) xEvent).getWindowID());
+ awtWindow = (Window) windows.get(key);
+ AWTEvent event = new WindowEvent(awtWindow, WindowEvent.WINDOW_STATE_CHANGED);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
break;
default:
if (XToolkit.DEBUG)
@@ -321,7 +369,7 @@ public class XEventPump
{
Input keyEvent = (Input) xEvent;
int xKeyCode = keyEvent.detail();
- int xMods = keyEvent.state();
+ int xMods = keyEvent.getState();
int keyCode = KeyboardMapping.mapToKeyCode(xEvent.display.input, xKeyCode,
xMods);
char keyChar = KeyboardMapping.mapToKeyChar(xEvent.display.input, xKeyCode,
diff --git a/gnu/java/awt/peer/x/XWindowPeer.java b/gnu/java/awt/peer/x/XWindowPeer.java
index 985c9af85..930247da5 100644
--- a/gnu/java/awt/peer/x/XWindowPeer.java
+++ b/gnu/java/awt/peer/x/XWindowPeer.java
@@ -71,23 +71,16 @@ public class XWindowPeer
private static int standardSelect = Event.BUTTON_PRESS_MASK
| Event.BUTTON_RELEASE_MASK
| Event.POINTER_MOTION_MASK
- //| Event.RESIZE_REDIRECT_MASK
+ // | Event.RESIZE_REDIRECT_MASK //
| Event.EXPOSURE_MASK
| Event.PROPERTY_CHANGE_MASK
- | Event.STRUCTURE_NOTIFY_MASK
- | Event.SUBSTRUCTURE_NOTIFY_MASK
+ //| Event.STRUCTURE_NOTIFY_MASK
+ //| Event.SUBSTRUCTURE_NOTIFY_MASK
| Event.KEY_PRESS_MASK
| Event.KEY_RELEASE_MASK
- //| Event.VISIBILITY_CHANGE_MASK
+ //| Event.VISIBILITY_CHANGE_MASK //
;
-
- /**
- * Indicates if we are in callback mode, that is when a property (like size)
- * is changed in reponse to a request from the X server and doesn't need
- * to be propagated back to the X server.
- */
- boolean callback = false;
-
+
/**
* The X window.
*/
@@ -273,14 +266,9 @@ public class XWindowPeer
*/
public void reshape(int x, int y, int width, int height)
{
- // Need to substract insets because AWT size is including insets,
- // and X size is excluding insets.
- if (! callback)
- {
- Insets i = insets;
- xwindow.move_resize(x - i.left, y - i.right, width - i.left - i.right,
- height - i.top - i.bottom);
- }
+ Insets i = insets;
+ xwindow.move_resize(x - i.left, y - i.right, width - i.left - i.right,
+ height - i.top - i.bottom);
}
public Insets insets()