Author: Conzar (posted 2012-04-24 16:07:38, viewed 152 times)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
| diff --git coreAPI/src/java/net/java/games/input/Keyboard.java coreAPI/src/java/net/java/games/input/Keyboard.java
index e168869..36dd634 100644
--- coreAPI/src/java/net/java/games/input/Keyboard.java
+++ coreAPI/src/java/net/java/games/input/Keyboard.java
-66,4 +66,8 @@ public abstract class Keyboard extends AbstractController {
return false;
return key.getPollData() != 0;
}
+
+ public boolean grab(){ return false; }
+
+ public boolean ungrab(){ return false;}
} diff --git coreAPI/src/java/net/java/games/input/Mouse.java coreAPI/src/java/net/java/games/input/Mouse.java
index 74301ff..5fe9cc7 100644
--- coreAPI/src/java/net/java/games/input/Mouse.java
+++ coreAPI/src/java/net/java/games/input/Mouse.java
-183,4 +183,8 @@ public abstract class Mouse extends AbstractController {
return getComponent(Component.Identifier.Button._4);
}
+ public boolean grab(){ return false; }
+
+ public boolean ungrab(){ return false;}
+
} diff --git plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
old mode 100755
new mode 100644
diff --git plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java
index fc829c9..1a1a85c 100644
--- plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java
+++ plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java
-480,6 +480,43 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
}
+
+ * Attempt to find devices using uinput used for forwarding events.
+ * TODO try to work this out!
+ */
+
+ private final void enumerateUInputControllers(List controllers) {
+ final File dev = new File("/dev/uinput");
+ File[] event_device_files = listFilesPrivileged(dev, new FilenameFilter() {
+ public final boolean accept(File dir, String name) {
+ return name.startsWith("event");
+ }
+ });
+ if (event_device_files == null)
+ return;
+ for (int i = 0; i < event_device_files.length; i++) {
+ File event_file = event_device_files[i];
+ try {
+ String path = getAbsolutePathPrivileged(event_file);
+ LinuxEventDevice device = new LinuxEventDevice(path);
+ try {
+ Controller controller = createControllerFromDevice(device);
+ if (controller != null) {
+ controllers.add(controller);
+ devices.add(device);
+ } else
+ device.close();
+ } catch (IOException e) {
+ logln("Failed to create Controller: " + e.getMessage());
+ device.close();
+ }
+ } catch (IOException e) {
+ logln("Failed to open device (" + event_file + "): " + e.getMessage());
+ }
+ }
+ }
+ */
+
private final class ShutdownHook extends Thread {
public final void run() {
for (int i = 0; i < devices.size(); i++) {
diff --git plugins/linux/src/java/net/java/games/input/LinuxEventDevice.java plugins/linux/src/java/net/java/games/input/LinuxEventDevice.java
index a28c4c7..1517147 100644
--- plugins/linux/src/java/net/java/games/input/LinuxEventDevice.java
+++ plugins/linux/src/java/net/java/games/input/LinuxEventDevice.java
-94,28 +94,6 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final Controller.Type guessType() throws IOException {
- Controller.Type type_from_usages = guessTypeFromUsages();
- if (type_from_usages == Controller.Type.UNKNOWN)
- return guessTypeFromComponents();
- else
- return type_from_usages;
- }
-
- private final Controller.Type guessTypeFromUsages() throws IOException {
- byte[] usage_bits = getDeviceUsageBits();
- if (isBitSet(usage_bits, NativeDefinitions.USAGE_MOUSE))
- return Controller.Type.MOUSE;
- else if (isBitSet(usage_bits, NativeDefinitions.USAGE_KEYBOARD))
- return Controller.Type.KEYBOARD;
- else if (isBitSet(usage_bits, NativeDefinitions.USAGE_GAMEPAD))
- return Controller.Type.GAMEPAD;
- else if (isBitSet(usage_bits, NativeDefinitions.USAGE_JOYSTICK))
- return Controller.Type.STICK;
- else
- return Controller.Type.UNKNOWN;
- }
-
- private final Controller.Type guessTypeFromComponents() throws IOException {
List components = getComponents();
if (components.size() == 0)
return Controller.Type.UNKNOWN;
-342,15 +320,6 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final static native void nGetBits(long fd, int ev_type, byte[] evtype_bits) throws IOException;
- private final byte[] getDeviceUsageBits() throws IOException {
- byte[] bits = new byte[NativeDefinitions.USAGE_MAX/8 + 1];
- if (getVersion() >= 0x010001) {
- nGetDeviceUsageBits(fd, bits);
- }
- return bits;
- }
- private final static native void nGetDeviceUsageBits(long fd, byte[] type_bits) throws IOException;
-
public final synchronized void pollKeyStates() throws IOException {
nGetKeyStates(fd, key_states);
}
-391,6 +360,36 @@ final class LinuxEventDevice implements LinuxDevice {
throw new IOException("Device is closed");
}
+ private final static native int nGrab(long fd, int grab) throws IOException;
+
+
+ * Grabs the device so that no other programs can read from the device.
+ */
+ public synchronized final boolean grab(){
+ try{
+ if(nGrab(fd,1) == 0){
+ return false;
+ }
+ }catch(IOException e){
+ return false;
+ }
+ return true;
+ }
+
+ * Release the event so other programs can get events.
+ */
+ public synchronized final boolean ungrab(){
+ try{
+ if(nGrab(fd,0) == 0){
+ return false;
+ }
+ }catch(IOException e){
+ return false;
+ }
+ return true;
+ }
+
+
protected void finalize() throws IOException {
close();
}
diff --git plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java
index 96b2d08..3795541 100644
--- plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java
+++ plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java
-65,4 +65,8 @@ final class LinuxKeyboard extends Keyboard {
public final void pollDevice() throws IOException {
device.pollKeyStates();
}
+
+ public boolean grab(){ return device.grab(); }
+
+ public boolean ungrab(){ return device.ungrab();}
}
diff --git plugins/linux/src/java/net/java/games/input/LinuxMouse.java plugins/linux/src/java/net/java/games/input/LinuxMouse.java
index 17b5895..4c3d208 100644
--- plugins/linux/src/java/net/java/games/input/LinuxMouse.java
+++ plugins/linux/src/java/net/java/games/input/LinuxMouse.java
-65,4 +65,8 @@ final class LinuxMouse extends Mouse {
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return LinuxControllers.getNextDeviceEvent(event, device);
}
+
+ public boolean grab(){ return device.grab(); }
+
+ public boolean ungrab(){ return device.ungrab();}
}
diff --git plugins/linux/src/native/net_java_games_input_LinuxEventDevice.c plugins/linux/src/native/net_java_games_input_LinuxEventDevice.c
index 90eff09..044c3dd 100644
--- plugins/linux/src/native/net_java_games_input_LinuxEventDevice.c
+++ plugins/linux/src/native/net_java_games_input_LinuxEventDevice.c
-112,20 +112,6 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNumEffects
return num_effects;
}
-JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetDeviceUsageBits(JNIEnv *env, jclass unused, jlong fd_address, jbyteArray usages_array) {
-#if EV_VERSION >= 0x010001
- int fd = (int)fd_address;
- jsize len = (*env)->GetArrayLength(env, usages_array);
- jbyte *usages = (*env)->GetByteArrayElements(env, usages_array, NULL);
- if (usages == NULL)
- return;
- int res = ioctl(fd, EVIOCGUSAGE(len), usages);
- (*env)->ReleaseByteArrayElements(env, usages_array, usages, 0);
- if (res == -1)
- throwIOException(env, "Failed to get device usages (%d)\n", errno);
-#endif
-}
-
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetBits(JNIEnv *env, jclass unused, jlong fd_address, jint evtype, jbyteArray bits_array) {
int fd = (int)fd_address;
jsize len = (*env)->GetArrayLength(env, bits_array);
-255,3 +241,18 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nEraseEffect(J
if (ioctl(fd, EVIOCRMFF, &ff_id_int) == -1)
throwIOException(env, "Failed to erase effect (%d)\n", errno);
}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGrab(JNIEnv *env, jclass unused, jlong fd_address, jint do_grab) {
+ int fd = (int)fd_address;
+ int grab = (int)do_grab;
+<<<<<<< HEAD
+ int version;
+ if (ioctl(fd,EVIOCGRAB,do_grab) == -1){
+=======
+ if (ioctl(fd,EVIOCGRAB,grab) == -1){
+>>>>>>> 835f3b36964d5a757ab4baea8240f1d56a97e375
+ throwIOException(env, "Failed to grab device (%d)\n", errno);
+ return -1;
+ }
+ return 1;
+} |
Special syntax:
- To highlight a line (yellow background), prefix it with '@@'
- To indicate that a line should be removed (red background), prefix it with '-'
- To indicate that a line should be added (green background), prefix it with '+'
- To post multiple snippets, seperate them by '~~~~'
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|