Skip to main content

Window API

The Window API provides methods to create, manage, and control application windows in NativePHP Desktop.

Opening Windows

Native\Desktop\Facades\Window::open()

Create a new window with the specified ID.
id
string
default:"main"
Unique identifier for the window
PendingOpenWindow
object
Returns a PendingOpenWindow instance for configuring the window before it opens
use Native\Desktop\Facades\Window;

// Open the main window
Window::open('main')
    ->title('My Application')
    ->url('https://example.com')
    ->width(800)
    ->height(600);

// Open a secondary window
Window::open('settings')
    ->title('Settings')
    ->route('settings')
    ->width(600)
    ->height(400);

Window Management

close()

Close a window by its ID.
id
string|null
default:"null"
Window ID to close. If null, closes the current window.
Window::close('settings');
Window::close(); // Closes current window

hide()

Hide a window without closing it.
id
string|null
default:"null"
Window ID to hide. If null, hides the current window.
Window::hide('main');

show()

Show a previously hidden window.
id
string|null
default:"null"
Window ID to show. If null, shows the current window.
Window::show('main');

current()

Get the current window instance.
Window
object
Returns the current Window object with all properties
$currentWindow = Window::current();
echo $currentWindow->id;
echo $currentWindow->title;

all()

Get all open windows.
windows
array
Returns an array of Window objects
$windows = Window::all();
foreach ($windows as $window) {
    echo $window->id;
}

get()

Get a specific window by its ID.
id
string
required
Window ID to retrieve
Window
object
Returns the Window object
$settingsWindow = Window::get('settings');

Window Sizing

resize()

Resize a window to the specified dimensions.
width
int
required
New width in pixels
height
int
required
New height in pixels
id
string|null
default:"null"
Window ID to resize. If null, resizes the current window.
Window::resize(1024, 768, 'main');

position()

Set the window position on screen.
x
int
required
X coordinate in pixels
y
int
required
Y coordinate in pixels
animated
bool
default:"false"
Whether to animate the position change
id
string|null
default:"null"
Window ID to position. If null, positions the current window.
Window::position(100, 100, true, 'main');

maximize()

Maximize a window.
id
string|null
default:"null"
Window ID to maximize. If null, maximizes the current window.
Window::maximize('main');

minimize()

Minimize a window.
id
string|null
default:"null"
Window ID to minimize. If null, minimizes the current window.
Window::minimize('main');

Window Behavior

alwaysOnTop()

Set whether the window should always stay on top of other windows.
alwaysOnTop
bool
default:"true"
Whether to keep window on top
id
string|null
default:"null"
Window ID. If null, applies to the current window.
Window::alwaysOnTop(true, 'main');

reload()

Reload the window’s content.
id
string|null
default:"null"
Window ID to reload. If null, reloads the current window.
Window::reload('main');

Window Configuration Methods

These methods are chainable and used when opening a window:

title()

Set the window title.
title
string
required
Window title text
Window::open()->title('My Application');

url()

Set the window URL.
url
string
required
Full URL to load in the window
Window::open()->url('https://example.com');

route()

Set the window URL using a Laravel route name.
route
string
required
Laravel route name
parameters
array
default:"[]"
Route parameters
Window::open()->route('dashboard');
Window::open()->route('user.profile', ['id' => 1]);

width()

Set the window width.
width
int
required
Width in pixels
Window::open()->width(800);

height()

Set the window height.
height
int
required
Height in pixels
Window::open()->height(600);

minWidth() / minHeight()

Set minimum dimensions for the window.
width
int
required
Minimum width in pixels
height
int
required
Minimum height in pixels
Window::open()
    ->minWidth(400)
    ->minHeight(300);

maxWidth() / maxHeight()

Set maximum dimensions for the window.
width
int
required
Maximum width in pixels
height
int
required
Maximum height in pixels
Window::open()
    ->maxWidth(1920)
    ->maxHeight(1080);

resizable()

Set whether the window can be resized.
resizable
bool
default:"true"
Whether window is resizable
Window::open()->resizable(false);

movable()

Set whether the window can be moved.
movable
bool
default:"true"
Whether window is movable
Window::open()->movable(false);

minimizable()

Set whether the window can be minimized.
minimizable
bool
default:"true"
Whether window is minimizable
Window::open()->minimizable(true);

maximizable()

Set whether the window can be maximized.
maximizable
bool
default:"true"
Whether window is maximizable
Window::open()->maximizable(true);

closable()

Set whether the window can be closed.
closable
bool
default:"true"
Whether window is closable
Window::open()->closable(true);

focusable()

Set whether the window can receive focus.
focusable
bool
default:"true"
Whether window is focusable
Window::open()->focusable(true);

alwaysOnTop()

Set whether the window stays on top of other windows.
alwaysOnTop
bool
default:"true"
Whether window stays on top
Window::open()->alwaysOnTop(true);

skipTaskbar()

Set whether to hide the window from the taskbar.
skipTaskbar
bool
default:"true"
Whether to skip taskbar
Window::open()->skipTaskbar(true);

hiddenInMissionControl()

Set whether to hide the window in macOS Mission Control.
hidden
bool
default:"true"
Whether to hide in Mission Control
Window::open()->hiddenInMissionControl(true);

hasShadow()

Set whether the window has a shadow.
hasShadow
bool
default:"true"
Whether window has shadow
Window::open()->hasShadow(false);

Window Appearance

frameless()

Create a window without a frame.
Window::open()->frameless();

titleBarStyle()

Set the title bar style.
style
string
required
Style: ‘default’, ‘hidden’, ‘hiddenInset’, ‘customButtonsOnHover’
Window::open()->titleBarStyle('hidden');

titleBarHidden()

Hide the title bar.
Window::open()->titleBarHidden();

titleBarHiddenInset()

Hide the title bar with inset style.
Window::open()->titleBarHiddenInset();

titleBarButtonsOnHover()

Show title bar buttons only on hover.
Window::open()->titleBarButtonsOnHover();

trafficLightPosition()

Set the position of macOS traffic light buttons.
x
int
required
X coordinate in pixels
y
int
required
Y coordinate in pixels
Window::open()->trafficLightPosition(20, 20);

trafficLightsHidden()

Hide the macOS traffic light buttons.
Window::open()->trafficLightsHidden();

windowButtonVisibility()

Set the visibility of window buttons.
visible
bool
default:"true"
Whether buttons are visible
Window::open()->windowButtonVisibility(false);

backgroundColor()

Set the window background color.
color
string
required
Hex color code (e.g., ‘#FFFFFF’)
Window::open()->backgroundColor('#1a1a1a');

transparent()

Make the window background transparent.
transparent
bool
default:"true"
Whether window is transparent
Window::open()->transparent();

vibrancy()

Set the vibrancy effect (macOS).
vibrancy
string
required
Vibrancy type: ‘appearance-based’, ‘light’, ‘dark’, ‘under-window’
Window::open()->vibrancy('dark');

lightVibrancy()

Apply light vibrancy effect.
Window::open()->lightVibrancy();

darkVibrancy()

Apply dark vibrancy effect.
Window::open()->darkVibrancy();

blendBackgroundBehindWindow()

Blend the content behind the window.
Window::open()->blendBackgroundBehindWindow();

invisibleFrameless()

Create an invisible frameless window (useful for overlays).
Window::open()->invisibleFrameless();

Developer Tools

showDevTools()

Show developer tools in the window.
show
bool
default:"true"
Whether to show dev tools
Window::open()->showDevTools();
$window->showDevTools(); // On existing window

hideDevTools()

Hide developer tools.
$window = Window::current();
$window->hideDevTools();

devToolsOpen()

Check if developer tools are open.
open
bool
Returns true if dev tools are open
$window = Window::current();
if ($window->devToolsOpen()) {
    // Dev tools are open
}

Fullscreen & Kiosk

fullscreen()

Set the window to fullscreen mode.
fullscreen
bool
default:"true"
Whether window is fullscreen
Window::open()->fullscreen();

fullscreenable()

Set whether the window can enter fullscreen.
fullscreenable
bool
default:"true"
Whether window can be fullscreen
Window::open()->fullscreenable(false);

kiosk()

Set the window to kiosk mode.
kiosk
bool
default:"true"
Whether window is in kiosk mode
Window::open()->kiosk();

hideMenu()

Auto-hide the menu bar.
autoHide
bool
default:"true"
Whether to auto-hide the menu bar
Window::open()->hideMenu();

Advanced Options

rememberState()

Remember window size and position between sessions.
Window::open()->rememberState();

zoomFactor()

Set the zoom level for the window content.
zoomFactor
float
default:"1.0"
Zoom factor (1.0 = 100%)
Window::open()->zoomFactor(1.5); // 150% zoom
$window->zoomFactor(0.8); // 80% zoom on existing window

webPreferences()

Set Electron web preferences.
preferences
array
required
Array of web preference options
Window::open()->webPreferences([
    'nodeIntegration' => false,
    'contextIsolation' => true,
]);

preventLeaveDomain()

Prevent navigation outside the application domain.
prevent
bool
default:"true"
Whether to prevent leaving domain
Window::open()->preventLeaveDomain();

preventLeavePage()

Prevent navigation away from the current page.
prevent
bool
default:"true"
Whether to prevent leaving page
Window::open()->preventLeavePage();

suppressNewWindows()

Suppress opening of new windows.
Window::open()->suppressNewWindows();

afterOpen()

Execute a callback after the window opens.
callback
callable
required
Callback function to execute
Window::open()
    ->afterOpen(function ($window) {
        // Window has opened
        Log::info('Window opened: ' . $window->getId());
    });

minimized()

Open the window minimized.
Window::open()->minimized();

maximized()

Open the window maximized.
Window::open()->maximized();

Complete Example

use Native\Desktop\Facades\Window;

// Create a customized window
Window::open('dashboard')
    ->title('Dashboard')
    ->route('dashboard')
    ->width(1200)
    ->height(800)
    ->minWidth(800)
    ->minHeight(600)
    ->titleBarHidden()
    ->trafficLightPosition(20, 20)
    ->vibrancy('dark')
    ->transparent()
    ->rememberState()
    ->showDevTools(config('app.debug'))
    ->preventLeaveDomain()
    ->afterOpen(function ($window) {
        Log::info('Dashboard window opened');
    });

// Get and manipulate existing window
$window = Window::get('dashboard');
$window->title('Dashboard - Updated');
$window->url(route('dashboard.updated'));

// Manage window state
Window::maximize('dashboard');
Window::position(0, 0, true, 'dashboard');

Build docs developers (and LLMs) love