@Override public long getSystemIdleTime () { X11.Window window = null; XScreenSaverInfo info = null; Display display = null; long idleMillis = 0L; try { display = X11.INSTANCE.XOpenDisplay(null); window = X11.INSTANCE.XDefaultRootWindow(display); info = new XScreenSaverInfo(); Xss.INSTANCE.XScreenSaverQueryInfo(display, window, info); idleMillis = info.idle.longValue(); } finally { info = null; if (display != null) X11.INSTANCE.XCloseDisplay(display); display = null; } return idleMillis; }
private void sendMessage (Display display, long mode, String msg) { X11 x = X11.INSTANCE; XEvent event = new XEvent(); event.type = X11.ClientMessage; event.setType(XClientMessageEvent.class); event.xclient.type = X11.ClientMessage; event.xclient.display = display; event.xclient.message_type = x.XInternAtom(display, _NET_WM_STATE, false); event.xclient.window = window; event.xclient.format = 32; event.xclient.data.setType(NativeLong[].class); event.xclient.data.l[0] = new NativeLong(mode); event.xclient.data.l[1] = x.XInternAtom(display, msg, false); NativeLong mask = new NativeLong(X11.SubstructureNotifyMask | X11.SubstructureRedirectMask); x.XSendEvent(display, x.XDefaultRootWindow(display), 0, mask, event); }
private void sendMessage (long mode, String msg) { X11 x = X11.INSTANCE; Display display = null; try { display = x.XOpenDisplay(null); sendMessage(display, mode, msg); } finally { if (display != null) { x.XCloseDisplay(display); } } }
@Override public long getIdleTimeMillis() { X11.Window window = null; XScreenSaverInfo info = null; Display display = null; long idleMillis = 0L; try { display = X11.INSTANCE.XOpenDisplay(null); if (display == null) { display = X11.INSTANCE.XOpenDisplay(":0.0"); } if (display == null) { throw new RuntimeException("Could not find a display, please setup your DISPLAY environment variable"); } window = X11.INSTANCE.XDefaultRootWindow(display); info = new XScreenSaverInfo(); Xss.INSTANCE.XScreenSaverQueryInfo(display, window, info); idleMillis = info.idle.longValue(); } catch(UnsatisfiedLinkError e) { throw new RuntimeException(e.getMessage(), e); } finally { info = null; if (display != null) { X11.INSTANCE.XCloseDisplay(display); } display = null; } return idleMillis; }
/** * On Linux by default the handling of mouse move, enter and leave event are not propagated. * Unfortunately the "handle-events" properties hide some important expose events too, * sowe've to do some lowlevel trick to be able to get these events. * In this case we (gstreamer-linux) must handle redraw too! * * @param enableX11Events true if X11 event should have to be grabbed (mouse move, enter and leave event on Linux). */ private void handleX11Events() { if (x11Events && Platform.isLinux()) { videosink.set("handle-events", !x11Events); overlay.handleEvent(!x11Events); watcherRunning = true; new Thread() { @Override public void run() { try { final X11 x11 = X11.INSTANCE; final Display display = x11.XOpenDisplay(null); Window window = new Window(nativeHandle); x11.XSelectInput(display, window, new NativeLong(X11.ExposureMask | X11.VisibilityChangeMask | X11.StructureNotifyMask | X11.FocusChangeMask | //X11.PointerMotionMask | X11.EnterWindowMask | X11.LeaveWindowMask)); while (watcherRunning) { final XEvent xEvent = new XEvent(); x11.XNextEvent(display, xEvent); if (watcherRunning && !isDisposed()) { getDisplay().asyncExec(new Runnable() { public void run() { if (watcherRunning && !isDisposed()) { final Event swtEvent = new Event(); XCrossingEvent ce; switch (xEvent.type) { // case X11.MotionNotify: // XMotionEvent e = (XMotionEvent)xEvent.readField("xmotion"); // swtEvent.x = e.x; // swtEvent.y = e.y; // notifyListeners(SWT.MouseMove, swtEvent); // break; case X11.EnterNotify: ce = (XCrossingEvent)xEvent.readField("xcrossing"); swtEvent.x = ce.x; swtEvent.y = ce.y; notifyListeners(SWT.MouseEnter, swtEvent); break; case X11.LeaveNotify: ce = (XCrossingEvent)xEvent.readField("xcrossing"); swtEvent.x = ce.x; swtEvent.y = ce.y; notifyListeners(SWT.MouseExit, swtEvent); break; default: overlay.expose(); } } } }); } } x11.XCloseDisplay(display); } catch (Exception e) { e.printStackTrace(); } } }.start(); } }
@Override public void setIcon (FileHandle iconCacheFolder, FileHandle icoFile, FileHandle pngFile) { Display display = null; try { display = x11.XOpenDisplay(null); Pixmap pixmap = new Pixmap(pngFile); if (pixmap.getWidth() != pixmap.getHeight()) { throw new IllegalStateException("Supplied icon image must be square"); } long buffer[] = new long[2 + pixmap.getWidth() * pixmap.getHeight()]; buffer[0] = pixmap.getWidth(); buffer[1] = pixmap.getHeight(); int bufIndex = 2; for (int i = 0; i < pixmap.getWidth(); i++) { for (int ii = 0; ii < pixmap.getHeight(); ii++) { int color = pixmap.getPixel(ii, i); //assuming pixmap is RGBA8888, buffer for x11 is ARGB8888 //probably not very optimized int r = ((color & 0xff000000) >>> 24); int g = ((color & 0x00ff0000) >>> 16); int b = ((color & 0x0000ff00) >>> 8); int a = ((color & 0x000000ff)); buffer[bufIndex++] = ((a << 24) | (r << 16) | (g << 8) | (b)); } } Window window = new Window(GLFWNativeX11.glfwGetX11Window(GLFW.glfwGetCurrentContext())); Pointer ptr = new Memory(buffer.length * 8); ptr.write(0, buffer, 0, buffer.length); x11.XChangeProperty(display, window, getAtom(display, _NET_WM_ICON), X11.XA_CARDINAL, 32, X11.PropModeReplace, ptr, buffer.length); pixmap.dispose(); } catch (Exception e) { throw new IllegalStateException(e); } finally { if (display != null) { x11.XCloseDisplay(display); } } }
private Atom getAtom (Display display, String atom_name) { return x11.XInternAtom(display, atom_name, false); }
/** Query the XScreensaver. * * @param display the display. * @param drawable a {@link Drawable} structure. * @param saver_info a previously allocated {@link XScreenSaverInfo} instance. * @return an int return code. */ int XScreenSaverQueryInfo (Display display, Drawable drawable, XScreenSaverInfo saver_info);
/** * Query the XScreensaver. * @param display the display. * @param drawable a {@link Drawable} structure. * @param saver_info a previously allocated {@link XScreenSaverInfo} instance. * @return an int return code. */ int XScreenSaverQueryInfo(Display display, Drawable drawable, XScreenSaverInfo saver_info);