Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public enum PreviewFeature {
// Add preview feature constants here:
// TEST_FEATURE("Test Feature")
STAGE_STYLE_EXTENDED("StageStyle.EXTENDED"),
HEADER_BAR("HeaderBar");
HEADER_BAR("HeaderBar"),
WINDOW_BACKDROP("WindowBackdrop");

PreviewFeature(String featureName) {
this.featureName = featureName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.application.preferences.PreferenceMapping;
import com.sun.javafx.stage.PlatformStageBackdrop;

import javafx.stage.StageBackdrop;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.LinkedList;
Expand Down Expand Up @@ -562,7 +566,14 @@ public void menuAboutAction() {
* allowed to be of exactly one visual kind, and exactly one functional
* type.
*/
public abstract Window createWindow(Window owner, Screen screen, int styleMask);
public abstract Window createWindow(Window owner, Screen screen, int styleMask, int backdropID);

/**
* Create a window with no backdrop.
*/
public final Window createWindow(Window owner, Screen screen, int styleMask) {
return createWindow(owner, screen, styleMask, Window.NO_BACKDROP_ID);
}

/**
* Create a window.
Expand All @@ -575,7 +586,7 @@ public void menuAboutAction() {
* type.
*/
public final Window createWindow(Screen screen, int styleMask) {
return createWindow(null, screen, styleMask);
return createWindow(null, screen, styleMask, Window.NO_BACKDROP_ID);
}

public abstract View createView();
Expand Down Expand Up @@ -719,6 +730,15 @@ public final boolean supportsExtendedWindows() {
return _supportsExtendedWindows();
}

protected boolean _supportsWindowBackdrops() {
return false;
}

public final boolean supportsWindowBackdrops() {
checkEventThread();
return _supportsWindowBackdrops();
}

protected boolean _supportsSystemMenu() {
// Overridden in subclasses
return false;
Expand Down Expand Up @@ -833,4 +853,26 @@ public static void overrideNativeWindowHandle(Class lwFrameWrapperClass, Object
public void showDocument(String uri) {
_showDocument(uri);
}

/**
* Return the list of backdrops supported on this platform.
* The default is an empty list.
*/
public List<String> getPlatformBackdropNames() {
return List.of();
}

/**
* Create a Platform backdrop for the specified name
*/
public PlatformStageBackdrop createPlatformBackdrop(String name) {
return null;
}

/**
* Return the platform identifier for the backdrop
*/
public int getBackdropIdentifier(StageBackdrop backdrop) {
return Window.NO_BACKDROP_ID;
}
}
26 changes: 23 additions & 3 deletions modules/javafx.graphics/src/main/java/com/sun/glass/ui/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ static protected void remove(Window window) {
*/
@Native public static final int DARK_FRAME = 1 << 11;

/**
* Indicates the window has no backdrop
*/
public static final int NO_BACKDROP_ID = -1;

final static public class State {
@Native public static final int NORMAL = 1;
@Native public static final int MINIMIZED = 2;
Expand Down Expand Up @@ -211,6 +216,7 @@ public static final class Level {
private final int styleMask;
private final boolean isDecorated;
private final boolean isPopup;
private final int backdropID;

protected View view = null;
protected Screen screen = null;
Expand Down Expand Up @@ -246,8 +252,8 @@ public static final class Level {

private EventHandler eventHandler;

protected abstract long _createWindow(long ownerPtr, long screenPtr, int mask);
protected Window(Window owner, Screen screen, int styleMask) {
protected abstract long _createWindow(long ownerPtr, long screenPtr, int mask, int backdropID);
protected Window(Window owner, Screen screen, int styleMask, int backdropID) {
Application.checkEventThread();
switch (styleMask & (TITLED | TRANSPARENT | EXTENDED)) {
case UNTITLED:
Expand Down Expand Up @@ -281,11 +287,16 @@ protected Window(Window owner, Screen screen, int styleMask) {
styleMask &= ~TRANSPARENT;
}

if (!Application.GetApplication().supportsWindowBackdrops()) {
backdropID = NO_BACKDROP_ID;
}

this.owner = owner;
this.styleMask = styleMask;
this.isDecorated = (this.styleMask & Window.TITLED) != 0;
this.isPopup = (this.styleMask & Window.POPUP) != 0;
this.isModal = (this.styleMask & Window.MODAL) != 0;
this.backdropID = backdropID;

this.screen = screen != null ? screen : Screen.getMainScreen();
if (PrismSettings.allowHiDPIScaling) {
Expand All @@ -296,12 +307,16 @@ protected Window(Window owner, Screen screen, int styleMask) {
}

this.ptr = _createWindow(owner != null ? owner.getNativeHandle() : 0L,
this.screen.getNativeScreen(), this.styleMask);
this.screen.getNativeScreen(), this.styleMask, this.backdropID);
if (this.ptr == 0L) {
throw new RuntimeException("could not create platform window");
}
}

protected Window(Window owner, Screen screen, int styleMask) {
this(owner, screen, styleMask, NO_BACKDROP_ID);
}

/**
* Specifies the preferred header button height. Sub-classes can use this value in their header button
* visualization, but they are not required to accommodate the preferred height.
Expand Down Expand Up @@ -750,6 +765,11 @@ public boolean isFocused() {
return this.isFocused;
}

public boolean hasBackdrop() {
// The backdrop is only set if backdrops are supported.
return (this.backdropID >= 0);
}

protected abstract boolean _requestFocus(long ptr, int event);
/**
* Requests or resigns focus on this window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected void _leaveNestedEventLoop(Object retValue) {
}

@Override
public Window createWindow(Window owner, Screen screen, int styleMask) {
public Window createWindow(Window owner, Screen screen, int styleMask, int backdropID) {
return new GtkWindow(owner, screen, styleMask);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public GtkWindow(Window owner, Screen screen, int styleMask) {
}

@Override
protected native long _createWindow(long ownerPtr, long screenPtr, int mask);
protected native long _createWindow(long ownerPtr, long screenPtr, int mask, int backdropID);

@Override
protected native boolean _close(long ptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected int _isKeyLocked(int keyCode) {
}

@Override
public Window createWindow(Window owner, Screen screen, int styleMask) {
public Window createWindow(Window owner, Screen screen, int styleMask, int backdropID) {
HeadlessWindow window = new HeadlessWindow(windowManager, owner, screen, frameBuffer, styleMask);
if (this.activeRobot != null) {
activeRobot.windowAdded(window);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public HeadlessWindow(HeadlessWindowManager wm, Window owner, Screen screen, Byt
}

@Override
protected long _createWindow(long ownerPtr, long screenPtr, int mask) {
protected long _createWindow(long ownerPtr, long screenPtr, int mask, int backdropID) {
this.ptr = ptrCount.incrementAndGet();
return ptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void setEventThread() {
* @inheritDoc
*/
@Override
public Window createWindow(Window owner, Screen screen, int styleMask) {
public Window createWindow(Window owner, Screen screen, int styleMask, int backdropID) {
return new IosWindow(owner, screen, styleMask);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected IosWindow(Window owner, Screen screen, int styleMask) {
}

// See Window for documentation
@Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask);
@Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask, int backdropID);
@Override native protected boolean _close(long ptr);
@Override native protected boolean _setView(long ptr, View view);
@Override native protected void _setBounds(long ptr, int x, int y, boolean xSet, boolean ySet, int w, int h, int cw, int ch, float xGravity, float yGravity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.application.preferences.PreferenceMapping;
import com.sun.javafx.stage.PlatformStageBackdrop;
import com.sun.javafx.util.Logging;
import javafx.scene.paint.Color;
import javafx.stage.StageBackdrop;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -279,8 +282,8 @@ public Menu getAppleMenu() {

// FACTORY METHODS

@Override public Window createWindow(Window owner, Screen screen, int styleMask) {
return new MacWindow(owner, screen, styleMask);
@Override public Window createWindow(Window owner, Screen screen, int styleMask, int backdropID) {
return new MacWindow(owner, screen, styleMask, backdropID);
}

@Override public View createView() {
Expand Down Expand Up @@ -404,6 +407,11 @@ protected boolean _supportsExtendedWindows() {
return true;
}

@Override
protected boolean _supportsWindowBackdrops() {
return true;
}

@Override protected boolean _supportsSystemMenu() {
return true;
}
Expand Down Expand Up @@ -542,4 +550,19 @@ public void checkPlatformPreferencesSupport() {
protected void _showDocument(String uri) {
_openURI(uri);
}

@Override
public List<String> getPlatformBackdropNames() {
return MacWindow.getPlatformBackdropNames();
}

@Override
public PlatformStageBackdrop createPlatformBackdrop(String name) {
return MacWindow.createPlatformBackdrop(name);
}

@Override
public int getBackdropIdentifier(StageBackdrop backdrop) {
return MacWindow.getBackdropIdentifier(backdrop);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@
import com.sun.glass.ui.Screen;
import com.sun.glass.ui.View;
import com.sun.glass.ui.Window;
import com.sun.javafx.stage.PlatformStageBackdrop;

import javafx.geometry.Dimension2D;
import javafx.scene.layout.HeaderBar;
import javafx.scene.paint.Color;
import javafx.stage.StageBackdrop;
import java.nio.ByteBuffer;
import java.lang.annotation.Native;
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;

/**
* MacOSX platform implementation class for Window.
Expand All @@ -45,15 +56,15 @@ final class MacWindow extends Window {
_initIDs();
}

protected MacWindow(Window owner, Screen screen, int styleMask) {
super(owner, screen, styleMask);
protected MacWindow(Window owner, Screen screen, int styleMask, int backdropID) {
super(owner, screen, styleMask, backdropID);

if (isExtendedWindow()) {
prefHeaderButtonHeightProperty().subscribe(this::onPrefHeaderButtonHeightChanged);
}
}

@Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask);
@Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask, int backdropID);
@Override native protected boolean _close(long ptr);
@Override native protected boolean _setView(long ptr, View view);
@Override native protected boolean _setMenubar(long ptr, long menubarPtr);
Expand Down Expand Up @@ -220,5 +231,69 @@ static NSWindowToolbarStyle ofHeight(double height) {
return SMALL;
}
}

final static public class BackdropID {
@Native public static final int WINDOW = 42;
@Native public static final int SIDEBAR = 43;
@Native public static final int MENU = 44;
@Native public static final int CLEARGLASS = 100;
}

private static Map<String, Integer> backdrops = null;

private static void initBackdrops() {
if (backdrops == null) {
backdrops = new HashMap<>();

backdrops.put("macOS.Window", BackdropID.WINDOW);
backdrops.put("macOS.Sidebar", BackdropID.SIDEBAR);
backdrops.put("macOS.Menu", BackdropID.MENU);

// Support for NSGlassEffectView must wait for the macOS 26 SDK
// try {
// var osVers = System.getProperty("os.version");
// String major = osVers.replaceFirst("(\\d+)\\.\\d+.*", "$1");
// int v = Integer.parseInt(major);
// if (v >= 26) {
// backdrops.put("macOS.ClearGlass", BackdropID.CLEARGLASS);
// }
// } catch (Exception e) {
// }
}
}

public static List<String> getPlatformBackdropNames() {
initBackdrops();
return Collections.unmodifiableList(new ArrayList<>(backdrops.keySet()));
}

public static PlatformStageBackdrop createPlatformBackdrop(String name) {
initBackdrops();
var id = backdrops.get(name);
if (id == null) {
return null;
}
var backdrop = new PlatformStageBackdrop(name);
if (name == "macOS.ClearGlass") {
backdrop.setAvailableOptions(Map.of("TintColor", Color.class, "CornerRadius", Number.class));
}

return backdrop;
}

public static int getBackdropIdentifier(StageBackdrop backdrop) {
if (backdrop == StageBackdrop.WINDOW) {
return BackdropID.WINDOW;
} else if (backdrop == StageBackdrop.PARTIAL) {
return BackdropID.SIDEBAR;
}

initBackdrops();
var id = backdrops.get(backdrop.getName());
if (id == null) {
return Window.NO_BACKDROP_ID;
}
return id;
}
}

Loading