FlixelHostIntegration
View sourceinterface
org.flixelgdx.backend.FlixelHostIntegration
Host platform integration for notifications, display management, and clipboard access.
This is separate from FlixelAlerter, which shows blocking dialog popups. Use Flixel.host from game code.
Desktop LWJGL3 ships a full implementation: freedesktop notify-send on Linux, osascript on macOS, WinRT toasts via PowerShell on Windows, GLFW window attention, AWT clipboard, and platform-specific screen wake lock. Web (TeaVM) implements the Browser Notification API, tab-title attention, the Screen Wake Lock API, the beforeunload exit guard, and the Clipboard API. Mobile builds use the safe no-op implementation.
Web notification permission
Browsers require explicit user permission before showing notifications. On the web backend, FlixelHostIntegration.supportsNotifications() returns false until permission has been granted. Call FlixelHostIntegration.requestNotificationPermission() early, ideally during a loading screen or in response to a user gesture before sending any notifications. On desktop, permission is implicit and FlixelHostIntegration.requestNotificationPermission() is a no-op.
Clipboard paste callbacks
Paste operations are asynchronous. Register a handler on FlixelHostIntegration.onTextPasted() before calling FlixelHostIntegration.pasteFromClipboard(). The signal fires once the platform has retrieved the data. Handlers may not be called on the GL thread; because of this, wrap any libGDX calls with Gdx.app.postRunnable(...).
Example:
// Notifications
Flixel.host.sendNotification("Ready", "Your level finished loading.");
Flixel.host.requestAttention();
// Clipboard (copy).
Flixel.host.copyToClipboard(saveCode);
// Clipboard (paste).
Flixel.host.onTextPasted().add(text -> {
if (text != null) {
Gdx.app.postRunnable(() -> saveCodeField.setText(text));
}
});
Flixel.host.pasteFromClipboard();
See Also: Flixel.host
Methods
requestNotificationPermission()
Prompts the user to grant notification permission for this origin.
On the web backend this triggers the browser permission dialog. It must be called in response to a user gesture (button press, key press, etc.) or the browser will silently ignore it. Once granted, FlixelHostIntegration.supportsNotifications() returns true and subsequent FlixelHostIntegration.sendNotification(String, String) calls will display toasts.
On desktop, permission is implicit and this method does nothing.
requestAttention()
Asks the window manager to highlight this app (taskbar entry flash, dock bounce, and similar).
On the web backend, this flashes the browser tab title while the tab is in the background.
keepScreenAwake(boolean)
Prevents the display from sleeping while the game is running.
Pass true to acquire a wake lock and false to release it. On desktop this uses platform-specific inhibit commands (caffeinate on macOS, systemd-inhibit or xdg-screensaver on Linux). On the web backend this uses the Screen Wake Lock API. Has no effect on platforms where FlixelHostIntegration.supportsWakeLock() returns false.
Parameters:
| Name | Description |
|---|---|
awake | true to keep the screen on, false to release the lock. |
setExitConfirmation(String)
Sets a message shown to the user when they attempt to close or navigate away from the game.
On the web backend this hooks window.beforeunload. Pass null to remove the guard. On desktop this is a no-op.
Parameters:
| Name | Description |
|---|---|
message | The warning message, or null to clear the exit guard. |
sendNotification(String, String)
Shows a non-blocking desktop notification using the platform provider (Action Center on Windows, Notification Center on macOS, D-Bus or libnotify on Linux, browser toasts on web).
On the web backend, notifications require prior permission. Call FlixelHostIntegration.requestNotificationPermission() first and confirm FlixelHostIntegration.supportsNotifications() returns true before calling this method.
Parameters:
| Name | Description |
|---|---|
title | Short title, or null to use a blank title when the OS allows it. |
message | Body text; must not be null. |
copyToClipboard(String)
Copies text to the system clipboard.
Has no effect on platforms where FlixelHostIntegration.supportsClipboard() returns false.
Parameters:
| Name | Description |
|---|---|
text | The text to copy; must not be null. |
pasteFromClipboard()
Requests a text read from the system clipboard.
The result is delivered asynchronously via FlixelHostIntegration.onTextPasted(). Register a handler on that signal before calling this method. If the clipboard is empty or does not contain text, the signal is not dispatched.
Has no effect on platforms where FlixelHostIntegration.supportsClipboard() returns false.
supportsNotifications()
Returns: true if FlixelHostIntegration.sendNotification(String, String) is expected to do useful work on this platform session. On the web backend, returns true only after FlixelHostIntegration.requestNotificationPermission() has been granted by the user.
supportsWakeLock()
Returns: true if FlixelHostIntegration.keepScreenAwake(boolean) is supported on this platform.
supportsClipboard()
Returns: true if text clipboard operations (FlixelHostIntegration.copyToClipboard(String) and FlixelHostIntegration.pasteFromClipboard()) are supported on this platform.
onTextPasted()
Signal dispatched when FlixelHostIntegration.pasteFromClipboard() resolves with text content.
The dispatched value is the pasted text. Handlers may be called off the GL thread. Wrap any libGDX calls with Gdx.app.postRunnable(...).
Returns: The signal; never null.