JNIEXPORT void JNICALL Java_com_turbovnc_vncviewer_Viewport_grabKeyboard (JNIEnv *env, jobject obj, jboolean on, jboolean pointer) { JAWT awt; JAWT_DrawingSurface *ds = NULL; JAWT_DrawingSurfaceInfo *dsi = NULL; JAWT_Win32DrawingSurfaceInfo *w32dsi = NULL; if (on) { awt.version = JAWT_VERSION_1_3; if (!handle) { if ((handle = LoadLibrary("jawt")) == NULL) _throww32(); if ((__JAWT_GetAWT = (__JAWT_GetAWT_type)GetProcAddress(handle, "JAWT_GetAWT")) == NULL) _throww32(); } if (__JAWT_GetAWT(env, &awt) == JNI_FALSE) _throw("Could not initialize AWT native interface"); if ((ds = awt.GetDrawingSurface(env, obj)) == NULL) _throw("Could not get drawing surface"); if ((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0) _throw("Could not lock surface"); if ((dsi = ds->GetDrawingSurfaceInfo(ds)) == NULL) _throw("Could not get drawing surface info"); if ((w32dsi = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo) == NULL) _throw("Could not get Win32 drawing surface info"); LowLevelHook::Activate(w32dsi->hwnd); printf("TurboVNC Helper: Grabbed keyboard for window 0x%.8llx\n", (unsigned long long)w32dsi->hwnd); } else { LowLevelHook::Deactivate(); printf("TurboVNC Helper: Ungrabbed keyboard\n"); } bailout: if (ds) { if (dsi) ds->FreeDrawingSurfaceInfo(dsi); ds->Unlock(ds); awt.FreeDrawingSurface(ds); } }
////////////////////////////////////////////////////////////////////// // Main ////////////////////////////////////////////////////////////////////// int main(int argc, char **argv) { int i; fprintf(stderr, "\n%s v%s (Build %s)\n\n", bench_name, __VERSION, __BUILD); if(argc>1) for(i=1; i<argc; i++) { if(!stricmp(argv[i], "-checkdb")) { checkdb=1; fprintf(stderr, "Checking double buffering. Watch for flashing to indicate that it is\n"); fprintf(stderr, "not enabled. Performance will be sub-optimal.\n"); } if(!stricmp(argv[i], "-noshm")) { doshm=0; } if(!stricmp(argv[i], "-verbose")) { fbx_printwarnings(stderr); } } try { #ifdef FBXWIN32 WNDCLASSEX wndclass; MSG msg; wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = GetModuleHandle(NULL); wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = bench_name; wndclass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); tryw32(RegisterClassEx(&wndclass)); width=GetSystemMetrics(SM_CXSCREEN); height=GetSystemMetrics(SM_CYSCREEN); #else if(!XInitThreads()) {fprintf(stderr, "ERROR: Could not initialize Xlib thread safety\n"); exit(1);} XSetErrorHandler(xhandler); if(!(wh.dpy=XOpenDisplay(0))) {fprintf(stderr, "Could not open display %s\n", XDisplayName(0)); exit(1);} width=DisplayWidth(wh.dpy, DefaultScreen(wh.dpy)); height=DisplayHeight(wh.dpy, DefaultScreen(wh.dpy)); #endif if(width<MIN_SCREEN_WIDTH && height<MIN_SCREEN_HEIGHT) { fprintf(stderr, "ERROR: Please switch to a screen resolution of at least %d x %d.\n", MIN_SCREEN_WIDTH, MIN_SCREEN_HEIGHT); exit(1); } width=WIDTH; height=HEIGHT; #ifdef FBXWIN32 int bw=GetSystemMetrics(SM_CXFIXEDFRAME)*2; int bh=GetSystemMetrics(SM_CYFIXEDFRAME)*2+GetSystemMetrics(SM_CYCAPTION); tryw32(wh=CreateWindowEx(0, bench_name, bench_name, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_VISIBLE, 0, 0, width+bw, height+bh, NULL, NULL, GetModuleHandle(NULL), NULL)); UpdateWindow(wh); BOOL ret; while(1) { if((ret=GetMessage(&msg, NULL, 0, 0))==-1) _throww32(); else if(ret==0) break; TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; #else XVisualInfo vtemp, *v=NULL; int n=0; XSetWindowAttributes swa; Window root=DefaultRootWindow(wh.dpy); vtemp.depth=24; vtemp.c_class=TrueColor; if((v=XGetVisualInfo(wh.dpy, VisualDepthMask|VisualClassMask, &vtemp, &n))!=NULL && n!=0) { swa.colormap=XCreateColormap(wh.dpy, root, v->visual, AllocNone); swa.border_pixel=0; swa.event_mask=0; errifnot(wh.win=XCreateWindow(wh.dpy, root, 0, 0, width, height, 0, v->depth, InputOutput, v->visual, CWBorderPixel|CWColormap|CWEventMask, &swa)); errifnot(XMapRaised(wh.dpy, wh.win)); XSync(wh.dpy, False); display(); XDestroyWindow(wh.dpy, wh.win); XFree(v); v=NULL; } else fprintf(stderr, "No RGB visuals available. Skipping those tests.\n\n"); vtemp.depth=8; vtemp.c_class=PseudoColor; if((v=XGetVisualInfo(wh.dpy, VisualDepthMask|VisualClassMask, &vtemp, &n))!=NULL && n!=0) { swa.colormap=XCreateColormap(wh.dpy, root, v->visual, AllocAll); swa.border_pixel=0; swa.event_mask=0; XColor xc[32]; int i; errifnot(v->colormap_size==256); for(i=0; i<32; i++) { xc[i].red=(i<16? i*16:255)<<8; xc[i].green=(i<16? i*16:255-(i-16)*16)<<8; xc[i].blue=(i<16? 255:255-(i-16)*16)<<8; xc[i].flags = DoRed | DoGreen | DoBlue; xc[i].pixel=i; } XStoreColors(wh.dpy, swa.colormap, xc, 32); errifnot(wh.win=XCreateWindow(wh.dpy, root, 0, 0, width, height, 0, v->depth, InputOutput, v->visual, CWBorderPixel|CWColormap|CWEventMask, &swa)); errifnot(XMapRaised(wh.dpy, wh.win)); XSync(wh.dpy, False); display(); XDestroyWindow(wh.dpy, wh.win); XFreeColormap(wh.dpy, swa.colormap); XFree(v); v=NULL; } else fprintf(stderr, "No Pseudocolor visuals available. Skipping those tests.\n\n"); return 0; #endif } catch(rrerror &e) {fprintf(stderr, "%s\n", e.getMessage());} }