01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Dmitry A. Durnev
19: * @version $Revision$
20: */package org.apache.harmony.awt.wtk.linux;
21:
22: import java.awt.Point;
23:
24: import org.apache.harmony.awt.nativebridge.CLongPointer;
25: import org.apache.harmony.awt.nativebridge.Int32Pointer;
26: import org.apache.harmony.awt.nativebridge.Int8Pointer;
27: import org.apache.harmony.awt.nativebridge.NativeBridge;
28: import org.apache.harmony.awt.nativebridge.linux.X11;
29: import org.apache.harmony.awt.wtk.NativeMouseInfo;
30:
31: /**
32: * Implementation of NativeMouseInfo for X11 platform.
33: */
34: public class LinuxMouseInfo implements NativeMouseInfo {
35:
36: private static final X11 x11 = X11.getInstance();
37: private static final NativeBridge bridge = NativeBridge
38: .getInstance();
39: final long display;
40: final int screen;
41:
42: LinuxMouseInfo(LinuxWindowFactory factory) {
43: display = factory.getDisplay();
44: screen = factory.getScreen();
45: }
46:
47: /**
48: * @see org.apache.harmony.awt.wtk.NativeMouseInfo#getLocation()
49: */
50: public Point getLocation() {
51: CLongPointer rootReturned = bridge.createCLongPointer(1, false);
52: CLongPointer childReturned = bridge
53: .createCLongPointer(1, false);
54: Int32Pointer rootX = bridge.createInt32Pointer(1, false);
55: Int32Pointer rootY = bridge.createInt32Pointer(1, false);
56: Int32Pointer windowX = bridge.createInt32Pointer(1, false);
57: Int32Pointer windowY = bridge.createInt32Pointer(1, false);
58: Int32Pointer mask = bridge.createInt32Pointer(1, false);
59:
60: long windowID = x11.XRootWindow(display, screen);
61:
62: x11.XQueryPointer(display, windowID, rootReturned,
63: childReturned, rootX, rootY, windowX, windowY, mask);
64:
65: return new Point(rootX.get(0), rootY.get(0));
66: }
67:
68: /**
69: * @see org.apache.harmony.awt.wtk.NativeMouseInfo#getNumberOfButtons()
70: */
71: public int getNumberOfButtons() {
72: int buttonCount = 1; // wild guess
73: Int8Pointer mapping = bridge.createInt8Pointer(buttonCount,
74: false);
75: buttonCount = x11.XGetPointerMapping(display, mapping,
76: buttonCount);
77: return ((buttonCount > 0) ? buttonCount : -1);
78: }
79:
80: }
|