Skip to content

@tmzt /callback.c
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#include <jni.h>
#ifdef HAVE_CONFIG_H
#include <kdrive-config.h>
#endif
#include "private.h"
#include <inputstr.h>
#include <mi.h>
CARD32 lastEventTime = 0;
EventList *androidEvents;
void androidCallbackKeyDown(void *kbdPtr, int keyCode) {
int i, n;
DeviceIntPtr kbd = kbdPtr;
LogMessage(X_DEFAULT, "[native] androidCallbackKeyDown: kbd: %.8x keyCode: %d", (unsigned int)kbd, keyCode);
GetEventList(&androidEvents);
//lastEventTime = GetTimeInMillis();
n = GetKeyboardEvents(androidEvents, kbd, KeyPress, keyCode);
LogMessage(X_DEFAULT, "[native] androidCallbackKeyDown: n: %d", n);
for (i = 0; i < n; i++) {
mieqEnqueue(kbd, (InternalEvent*)(androidEvents + i)->event);
// mieqProcessDeviceEvent(kbd, (InternalEvent*)(androidEvents + i)->event, NULL);
LogMessage(X_DEFAULT, "[native] androidCallbackKeyDown: enqueueing event KeyPress %d", keyCode);
};
//KdEnqueueKeyboardEvent (kbd, keyCode, FALSE);
}
void androidCallbackKeyUp(void *kbdPtr, int keyCode) {
int i, n;
DeviceIntPtr kbd = kbdPtr;
LogMessage(X_DEFAULT, "[native] androidCallbackKeyUp: kbd: %p keyCode: %d", kbd, keyCode);
GetEventList(&androidEvents);
//lastEventTime = GetTimeInMillis();
n = GetKeyboardEvents(androidEvents, kbd, KeyRelease, keyCode);
LogMessage(X_DEFAULT, "[native] androidCallbackKeyUp: n: %d", n);
for (i = 0; i < n; i++) {
mieqEnqueue(kbd, (InternalEvent*)(androidEvents + i)->event);
// mieqProcessDeviceEvent(kbd, (InternalEvent*)(androidEvents + i)->event, NULL);
LogMessage(X_DEFAULT, "[native] androidCallbackKeyUp: enqueueing event KeyRelease %d", keyCode);
};
//KdEnqueueKeyboardEvent (kbd, keyCode, TRUE);
}
void androidCallbackTouchDown(void *mousePtr, int x, int y) {
int i, n;
int v[3] = {x, y, 1};
DeviceIntPtr mouse = mousePtr;
LogMessage(X_DEFAULT, "[native] androidCallbackTouchDown: mouse: %p x: %d y: %d", mouse, x, y);
GetEventList(&androidEvents);
n = GetPointerEvents(androidEvents, mouse, MotionNotify | ButtonPress, 1, POINTER_ABSOLUTE, 0, 2, v);
LogMessage(X_DEFAULT, "[native] andriodCallbackTouchDown mouse->enabled: %d", mouse->enabled);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchDown: n: %d", n);
for (i = 0; i < n; i++) {
mieqEnqueue(mouse, (InternalEvent*)(androidEvents + i)->event);
// mieqProcessDeviceEvent(mouse, (InternalEvent*)(androidEvents + i)->event, NULL);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchDown: enqueueing event MotionNotify %d %d %d", x, y, 1);
};
n = GetPointerEvents(androidEvents, mouse, ButtonPress, 1, POINTER_ABSOLUTE, 0, 2, v);
for (i = 0; i < n; i++) {
mieqEnqueue(mouse, (InternalEvent*)(androidEvents + i)->event);
// mieqProcessDeviceEvent(mouse, (InternalEvent*)(androidEvents + i)->event, NULL);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchDown: enqueueing event ButtonPress buttons: %d", 1);
};
}
void androidCallbackTouchUp(void *mousePtr, int x, int y) {
int i, n;
int v[3] = {x, y, 0};
DeviceIntPtr mouse = mousePtr;
LogMessage(X_DEFAULT, "[native] androidCallbackTouchUp: mouse: %p x: %d y: %d", mouse, x, y);
GetEventList(&androidEvents);
n = GetPointerEvents(androidEvents, mouse, MotionNotify | ButtonRelease, 1, POINTER_ABSOLUTE, 0, 2, v);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchUp mouse->enable: %d", mouse->enabled);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchUp: n: %d", n);
for (i = 0; i < n; i++) {
mieqEnqueue(mouse, (InternalEvent*)(androidEvents + i)->event);
// mieqProcessDeviceEvent(mouse, (InternalEvent*)(androidEvents + i)->event, NULL);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchUp: enqueueing event MotionNotify %d %d %d", x, y, 0);
};
n = GetPointerEvents(androidEvents, mouse, ButtonRelease, 1, POINTER_ABSOLUTE, 0, 2, v);
for (i = 0; i < n; i++) {
mieqEnqueue(mouse, (InternalEvent*)(androidEvents + i)->event);
// mieqProcessDeviceEvent(mouse, (InternalEvent*)(androidEvents + i)->event, NULL);
LogMessage(X_DEFAULT, "[native] androidCallbackTouchDown: enqueueing event ButtonPress buttons: %d", 1);
};
}
/*
Copyright 2010 Timothy Meade
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "../android.h"
void androidInitNative(JavaVM *jvm) {
JNIEnv *jni_env;
jclass AndroiXService_class;
jfieldID blitview_id;
jclass AndroiXBlitView_class;
jobject blitview;
Android->jvm = jvm;
(*(Android->jvm))->AttachCurrentThread(Android->jvm, &jni_env, NULL);
AndroiXService_class = (*jni_env)->FindClass(jni_env, "net/homeip/ofn/androix/AndroiXService");
LOG("[native] init: local AndroiXService_class: %p", AndroiXService_class);
blitview_id = (*jni_env)->GetStaticFieldID(jni_env, AndroiXService_class, "blitView", "Lnet/homeip/ofn/androix/AndroiXBlitView;");
blitview = (*jni_env)->GetStaticObjectField(jni_env, AndroiXService_class, blitview_id);
LOG("[native] init: local blitview: %p", blitview);
AndroiXBlitView_class = (*jni_env)->GetObjectClass(jni_env, blitview);
LOG("[native] init: local AndroiXBlitView_class: %p", AndroiXBlitView_class);
/* setup global references and cache methodIDs */
Android->AndroiXService_class = (*jni_env)->NewGlobalRef(jni_env, AndroiXService_class);
Android->AndroiXBlitView_class = (*jni_env)->NewGlobalRef(jni_env, AndroiXBlitView_class);
Android->blitview = (*jni_env)->NewGlobalRef(jni_env, blitview);
Android->initNativeScreen = (*jni_env)->GetMethodID(jni_env, Android->AndroiXBlitView_class, "initNativeScreen", "(I)I");
Android->initNativeKeyboard = (*jni_env)->GetMethodID(jni_env, Android->AndroiXBlitView_class, "initNativeKeyboard", "(I)I");
Android->initNativeMouse = (*jni_env)->GetMethodID(jni_env, Android->AndroiXBlitView_class, "initNativeMouse", "(I)I");
Android->initFramebuffer = (*jni_env)->GetMethodID(jni_env, Android->AndroiXBlitView_class, "initFramebuffer", "(IIILjava/nio/ByteBuffer;)I");
Android->draw = (*jni_env)->GetMethodID(jni_env, Android->AndroiXBlitView_class, "draw", "(IIII)V");
(*jni_env)->DeleteLocalRef(jni_env, AndroiXService_class);
(*jni_env)->DeleteLocalRef(jni_env, AndroiXBlitView_class);
(*jni_env)->DeleteLocalRef(jni_env, blitview);
};
void androidInitNativeScreen(void *screen) {
JNIEnv *jni_env;
(*(Android->jvm))->AttachCurrentThread(Android->jvm, &jni_env, NULL);
(*jni_env)->CallIntMethod(jni_env, Android->blitview, Android->initNativeScreen, screen);
};
int androidInitNativeKeyboard(void *keyboard) {
JNIEnv *jni_env;
(*(Android->jvm))->AttachCurrentThread(Android->jvm, &jni_env, NULL);
LOG("[native] androidInitNativeKeyboard: keyboard: %p", keyboard);
return (*jni_env)->CallIntMethod(jni_env, Android->blitview, Android->initNativeKeyboard, keyboard);
};
int androidInitNativeMouse(void *mouse) {
JNIEnv *jni_env;
(*(Android->jvm))->AttachCurrentThread(Android->jvm, &jni_env, NULL);
LOG("[native] androidInitNativeMouse: mouse: %p", mouse);
return (*jni_env)->CallIntMethod(jni_env, Android->blitview, Android->initNativeMouse, mouse);
};
int androidInitNativeFramebuffer(void *base, void **bufPtr, int width, int height, int depth) {
JNIEnv *jni_env;
jobject *buf = (jobject *)bufPtr;
(*(Android->jvm))->AttachCurrentThread(Android->jvm, &jni_env, NULL);
int bpp = depth/8;
LOG("[native] androidInitNativeFramebuffer: base: %p buf: %p width: %d height: %d bpp: %d", base, buf, width, height, bpp);
buf = (*jni_env)->NewDirectByteBuffer(jni_env, base, (width*height*bpp));
jint res = (*jni_env)->CallIntMethod(jni_env, Android->blitview, Android->initFramebuffer, width, height, depth, buf);
return res;
};
void androidDraw(int x, int y, int w, int h) {
JNIEnv *jni_env;
jmethodID initNativeMouse;
LOG("[native] androidDraw: %d,%d %d x %d", x, y, w, h);
(*(Android->jvm))->AttachCurrentThread(Android->jvm, &jni_env, NULL);
(*jni_env)->CallVoidMethod(jni_env, Android->blitview, Android->draw, x, y, w, h);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.