public boolean postProcessKeyEvent(KeyEvent e) { // Processing events only if we are in the focused window but // we are not focus owner since otherwise we will get // duplicate shortcut events in the client - one is from // activate_accelerator, another from forwarded event // FIXME: This is probably an incompatibility, protocol // doesn't say anything about disable accelerators when client // is focused. XWindowPeer parent = getToplevelXWindow(); if (parent == null || !((Window) parent.getTarget()).isFocused() || target.isFocusOwner()) { return false; } boolean result = false; if (xembedLog.isLoggable(PlatformLogger.FINER)) xembedLog.finer("Post-processing event " + e); // Process ACCELERATORS AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e); long accel_id = 0; boolean exists = false; synchronized (ACCEL_LOCK) { exists = accel_lookup.containsKey(stroke); if (exists) { accel_id = accel_lookup.get(stroke).longValue(); } } if (exists) { if (xembedLog.isLoggable(PlatformLogger.FINE)) xembedLog.fine("Activating accelerator " + accel_id); xembed.sendMessage( xembed.handle, XEMBED_ACTIVATE_ACCELERATOR, accel_id, 0, 0); // FIXME: How about overloaded? result = true; } // Process Grabs, unofficial GTK feature exists = false; GrabbedKey key = new GrabbedKey(e); synchronized (GRAB_LOCK) { exists = grabbed_keys.contains(key); } if (exists) { if (xembedLog.isLoggable(PlatformLogger.FINE)) xembedLog.fine("Forwarding grabbed key " + e); forwardKeyEvent(e); result = true; } return result; }
public void handleWindowFocusOut(Window oppositeWindow, long serial) { Window actualFocusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow(); // If the actual focused window is not this decorated window then retain it. if (actualFocusedWindow != null && actualFocusedWindow != target) { Window owner = XWindowPeer.getDecoratedOwner(actualFocusedWindow); if (owner != null && owner == target) { setActualFocusedWindow((XWindowPeer) ComponentAccessor.getPeer(actualFocusedWindow)); } } super.handleWindowFocusOut(oppositeWindow, serial); }
public boolean requestWindowFocus(long time, boolean timeProvided) { focusLog.fine("Request for decorated window focus"); // If this is Frame or Dialog we can't assure focus request success - but we still can try // If this is Window and its owner Frame is active we can be sure request succedded. Window win = (Window) target; Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow(); Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow); focusLog.log( Level.FINER, "Current window is: active={0}, focused={1}", new Object[] {Boolean.valueOf(win == activeWindow), Boolean.valueOf(win == focusedWindow)}); XWindowPeer toFocus = this; while (toFocus.nextTransientFor != null) { toFocus = toFocus.nextTransientFor; } if (this == toFocus) { if (focusAllowedFor()) { if (win == activeWindow && win != focusedWindow) { // Happens when focus is on window child focusLog.fine("Focus is on child window - transfering it back"); handleWindowFocusInSync(-1); } else { focusLog.fine("Requesting focus to this window"); if (timeProvided) { requestXFocus(time); } else { requestXFocus(); } } return true; } else { return false; } } else if (toFocus.focusAllowedFor()) { focusLog.fine("Requesting focus to " + toFocus); if (timeProvided) { toFocus.requestXFocus(time); } else { toFocus.requestXFocus(); } return false; } else { // This might change when WM will have property to determine focus policy. // Right now, because policy is unknown we can't be sure we succedded return false; } }
void preInit(XCreateWindowParams params) { super.preInit(params); if (!resize_request.isInterned()) { resize_request.intern(false); } winAttr.initialFocus = true; currentInsets = new Insets(0, 0, 0, 0); // replacemenet for wdata->top, left, bottom, right applyGuessedInsets(); Rectangle bounds = (Rectangle) params.get(BOUNDS); dimensions = new WindowDimensions(bounds, getRealInsets(), false); params.put(BOUNDS, dimensions.getClientRect()); if (insLog.isLoggable(Level.FINE)) { insLog.log(Level.FINE, "Initial dimensions {0}", new Object[] {String.valueOf(dimensions)}); } // Deny default processing of these events on the shell - proxy will take care of // them instead Long eventMask = (Long) params.get(EVENT_MASK); params.add( EVENT_MASK, Long.valueOf(eventMask.longValue() & ~(FocusChangeMask | KeyPressMask | KeyReleaseMask))); }
public void handleWindowFocusIn(long serial) { if (null == actualFocusedWindow) { super.handleWindowFocusIn(serial); } else { /* * Fix for 6314575. * If this is a result of clicking on one of the Frame's component * then 'actualFocusedWindow' shouldn't be focused. A decision of focusing * it or not should be made after the appropriate Java mouse event (if any) * is handled by the component where 'actualFocusedWindow' value may be reset. * * The fix is based on the empiric fact consisting in that the component * receives native mouse event nearly at the same time the Frame receives * WM_TAKE_FOCUS (when FocusIn is generated via XSetInputFocus call) but * definetely before the Frame gets FocusIn event (when this method is called). */ postEvent( new InvocationEvent( target, new Runnable() { public void run() { XWindowPeer fw = null; synchronized (getStateLock()) { fw = actualFocusedWindow; actualFocusedWindow = null; if (null == fw || !fw.isVisible() || !fw.isFocusableWindow()) { fw = XDecoratedPeer.this; } } fw.handleWindowFocusIn_Dispatch(); } })); } }
public void handleFocusEvent(XEvent xev) { super.handleFocusEvent(xev); XFocusChangeEvent xfe = xev.get_xfocus(); // If we somehow received focus events forward it instead to proxy // FIXME: Shouldn't we instead check for inferrior? focusLog.finer("Received focus event on shell: " + xfe); // focusProxy.xRequestFocus(); }
public void setVisible(boolean vis) { if (log.isLoggable(Level.FINER)) { log.log( Level.FINER, "Setting {0} to visible {1}", new Object[] {String.valueOf(this), Boolean.valueOf(vis)}); } if (vis && !isVisible()) { XWM.setShellDecor(this); super.setVisible(vis); if (winAttr.isResizable) { // Fix for 4320050: Minimum size for java.awt.Frame is not being enforced. // We need to update frame's minimum size, not to reset it XWM.removeSizeHints(this, XlibWrapper.PMaxSize); updateMinimumSize(); } } else { super.setVisible(vis); } }
public void dispose() { if (content != null) { content.destroy(); } focusProxy.destroy(); if (iconWindow != null) { iconWindow.destroy(); } super.dispose(); }
void postInit(XCreateWindowParams params) { super.postInit(params); // The lines that follow need to be in a postInit, so they // happen after the X window is created. initResizability(); updateSizeHints(dimensions); content = createContent(dimensions); content.initialize(); if (warningWindow != null) { warningWindow.toFront(); } focusProxy = createFocusProxy(); }
void updateWMName() { super.updateWMName(); String name = getWMName(); XToolkit.awtLock(); try { if (name == null || name.trim().equals("")) { name = "Java"; } XAtom iconNameAtom = XAtom.get(XAtom.XA_WM_ICON_NAME); iconNameAtom.setProperty(getWindow(), name); XAtom netIconNameAtom = XAtom.get("_NET_WM_ICON_NAME"); netIconNameAtom.setPropertyUTF8(getWindow(), name); } finally { XToolkit.awtUnlock(); } }
public void handleClientMessage(XEvent xev) { super.handleClientMessage(xev); XClientMessageEvent cl = xev.get_xclient(); if ((wm_protocols != null) && (cl.get_message_type() == wm_protocols.getAtom())) { if (cl.get_data(0) == wm_delete_window.getAtom()) { handleQuit(); } else if (cl.get_data(0) == wm_take_focus.getAtom()) { handleWmTakeFocus(cl); } } else if (cl.get_message_type() == resize_request.getAtom()) { reshape( (int) cl.get_data(0), (int) cl.get_data(1), (int) cl.get_data(2), (int) cl.get_data(3), (int) cl.get_data(4), true); } }
public void updateMinimumSize() { super.updateMinimumSize(); updateMinSizeHints(); }
protected void startDrag(Transferable transferable, long[] formats, Map formatMap) { Component component = getTrigger().getComponent(); Component c = null; XWindowPeer wpeer = null; for (c = component; c != null && !(c instanceof Window); c = AWTAccessor.getComponentAccessor().getParent(c)) ; if (c instanceof Window) { wpeer = (XWindowPeer) c.getPeer(); } if (wpeer == null) { throw new InvalidDnDOperationException("Cannot find top-level for the drag source component"); } long xcursor = 0; long rootWindow = 0; long dragWindow = 0; long timeStamp = 0; /* Retrieve the X cursor for the drag operation. */ { Cursor cursor = getCursor(); if (cursor != null) { xcursor = XGlobalCursorManager.getCursor(cursor); } } XToolkit.awtLock(); try { if (proxyModeSourceWindow != 0) { throw new InvalidDnDOperationException("Proxy drag in progress"); } if (dndInProgress) { throw new InvalidDnDOperationException("Drag in progress"); } /* Determine the root window for the drag operation. */ { long screen = XlibWrapper.XScreenNumberOfScreen(wpeer.getScreen()); rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen); } dragWindow = XWindow.getXAWTRootWindow().getWindow(); timeStamp = XToolkit.getCurrentServerTime(); int dropActions = getDragSourceContext().getSourceActions(); Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols(); while (dragProtocols.hasNext()) { XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols.next(); try { dragProtocol.initializeDrag( dropActions, transferable, formatMap, formats); } catch (XException xe) { throw (InvalidDnDOperationException) new InvalidDnDOperationException().initCause(xe); } } /* Install X grabs. */ { int status; XWindowAttributes wattr = new XWindowAttributes(); try { status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), rootWindow, wattr.pData); if (status == 0) { throw new InvalidDnDOperationException("XGetWindowAttributes failed"); } rootEventMask = wattr.get_your_event_mask(); XlibWrapper.XSelectInput( XToolkit.getDisplay(), rootWindow, rootEventMask | ROOT_EVENT_MASK); } finally { wattr.dispose(); } XBaseWindow.ungrabInput(); status = XlibWrapper.XGrabPointer( XToolkit.getDisplay(), rootWindow, 0, GRAB_EVENT_MASK, XConstants.GrabModeAsync, XConstants.GrabModeAsync, XConstants.None, xcursor, timeStamp); if (status != XConstants.GrabSuccess) { cleanup(timeStamp); throwGrabFailureException("Cannot grab pointer", status); return; } status = XlibWrapper.XGrabKeyboard( XToolkit.getDisplay(), rootWindow, 0, XConstants.GrabModeAsync, XConstants.GrabModeAsync, timeStamp); if (status != XConstants.GrabSuccess) { cleanup(timeStamp); throwGrabFailureException("Cannot grab keyboard", status); return; } } /* Update the global state. */ dndInProgress = true; dragInProgress = true; dragRootWindow = rootWindow; sourceActions = dropActions; sourceFormats = formats; } finally { XToolkit.awtUnlock(); } /* This implementation doesn't use native context */ setNativeContext(0); SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable); }