Java 类com.sun.jna.platform.unix.X11.XEvent 实例源码

项目:arget    文件:X11IconFlasher.java   
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);
}
项目:gstreamer1.x-java    文件:VideoComponent.java   
/**
     * 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();
        }
    }