pub struct Window<R: Runtime = Wry> { /* private fields */ }
Expand description
A window managed by Tauri.
This type also implements Manager
which allows you to manage other windows attached to
the same application.
Implementations§
Source§impl<R: Runtime> Window<R>
impl<R: Runtime> Window<R>
Base window functions.
Sourcepub fn builder<M: Manager<R>, L: Into<String>>(
manager: &M,
label: L,
) -> WindowBuilder<'_, R, M>
Available on crate feature unstable
only.
pub fn builder<M: Manager<R>, L: Into<String>>( manager: &M, label: L, ) -> WindowBuilder<'_, R, M>
unstable
only.Initializes a window builder with the given window label.
Data URLs are only supported with the webview-data-url
feature flag.
Sourcepub fn run_on_main_thread<F: FnOnce() + Send + 'static>(
&self,
f: F,
) -> Result<()>
pub fn run_on_main_thread<F: FnOnce() + Send + 'static>( &self, f: F, ) -> Result<()>
Runs the given closure on the main thread.
Sourcepub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F)
pub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F)
Registers a window event listener.
Source§impl<R: Runtime> Window<R>
impl<R: Runtime> Window<R>
Window getters.
Sourcepub fn scale_factor(&self) -> Result<f64>
pub fn scale_factor(&self) -> Result<f64>
Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
Sourcepub fn inner_position(&self) -> Result<PhysicalPosition<i32>>
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>>
Returns the position of the top-left hand corner of the window’s client area relative to the top-left hand corner of the desktop.
Sourcepub fn outer_position(&self) -> Result<PhysicalPosition<i32>>
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>>
Returns the position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
Sourcepub fn inner_size(&self) -> Result<PhysicalSize<u32>>
pub fn inner_size(&self) -> Result<PhysicalSize<u32>>
Returns the physical size of the window’s client area.
The client area is the content of the window, excluding the title bar and borders.
Sourcepub fn outer_size(&self) -> Result<PhysicalSize<u32>>
pub fn outer_size(&self) -> Result<PhysicalSize<u32>>
Returns the physical size of the entire window.
These dimensions include the title bar and borders. If you don’t want that (and you usually don’t), use inner_size instead.
Sourcepub fn is_fullscreen(&self) -> Result<bool>
pub fn is_fullscreen(&self) -> Result<bool>
Gets the window’s current fullscreen state.
Sourcepub fn is_minimized(&self) -> Result<bool>
pub fn is_minimized(&self) -> Result<bool>
Gets the window’s current minimized state.
Sourcepub fn is_maximized(&self) -> Result<bool>
pub fn is_maximized(&self) -> Result<bool>
Gets the window’s current maximized state.
Sourcepub fn is_focused(&self) -> Result<bool>
pub fn is_focused(&self) -> Result<bool>
Gets the window’s current focus state.
Sourcepub fn is_decorated(&self) -> Result<bool>
pub fn is_decorated(&self) -> Result<bool>
Gets the window’s current decoration state.
Sourcepub fn is_resizable(&self) -> Result<bool>
pub fn is_resizable(&self) -> Result<bool>
Gets the window’s current resizable state.
Sourcepub fn is_enabled(&self) -> Result<bool>
pub fn is_enabled(&self) -> Result<bool>
Whether the window is enabled or disabled.
Sourcepub fn is_maximizable(&self) -> Result<bool>
pub fn is_maximizable(&self) -> Result<bool>
Gets the window’s native maximize button state
§Platform-specific
- Linux / iOS / Android: Unsupported.
Sourcepub fn is_minimizable(&self) -> Result<bool>
pub fn is_minimizable(&self) -> Result<bool>
Gets the window’s native minimize button state
§Platform-specific
- Linux / iOS / Android: Unsupported.
Sourcepub fn is_closable(&self) -> Result<bool>
pub fn is_closable(&self) -> Result<bool>
Sourcepub fn is_visible(&self) -> Result<bool>
pub fn is_visible(&self) -> Result<bool>
Gets the window’s current visibility state.
Sourcepub fn current_monitor(&self) -> Result<Option<Monitor>>
pub fn current_monitor(&self) -> Result<Option<Monitor>>
Returns the monitor on which the window currently resides.
Returns None if current monitor can’t be detected.
Sourcepub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>
pub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>
Returns the monitor that contains the given point.
Sourcepub fn primary_monitor(&self) -> Result<Option<Monitor>>
pub fn primary_monitor(&self) -> Result<Option<Monitor>>
Returns the primary monitor of the system.
Returns None if it can’t identify any monitor as a primary one.
Sourcepub fn available_monitors(&self) -> Result<Vec<Monitor>>
pub fn available_monitors(&self) -> Result<Vec<Monitor>>
Returns the list of all the monitors available on the system.
Trait Implementations§
Source§impl<'de, R: Runtime> CommandArg<'de, R> for Window<R>
impl<'de, R: Runtime> CommandArg<'de, R> for Window<R>
Source§fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
Grabs the Window
from the CommandItem
. This will never fail.
Source§impl<R: Runtime> Emitter<R> for Window<R>
impl<R: Runtime> Emitter<R> for Window<R>
Source§fn emit_to<I, S>(&self, target: I, event: &str, payload: S) -> Result<()>
fn emit_to<I, S>(&self, target: I, event: &str, payload: S) -> Result<()>
Emits an event to all targets matching the given target.
§Examples
use tauri::{Emitter, EventTarget};
#[tauri::command]
fn download(window: tauri::Window) {
for i in 1..100 {
std::thread::sleep(std::time::Duration::from_millis(150));
// emit a download progress event to all listeners
window.emit_to(EventTarget::any(), "download-progress", i);
// emit an event to listeners that used App::listen or AppHandle::listen
window.emit_to(EventTarget::app(), "download-progress", i);
// emit an event to any webview/window/webviewWindow matching the given label
window.emit_to("updater", "download-progress", i); // similar to using EventTarget::labeled
window.emit_to(EventTarget::labeled("updater"), "download-progress", i);
// emit an event to listeners that used WebviewWindow::listen
window.emit_to(EventTarget::webview_window("updater"), "download-progress", i);
}
}
Source§fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>
fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>
Emits an event to all targets based on the given filter.
§Examples
use tauri::{Emitter, EventTarget};
#[tauri::command]
fn download(window: tauri::Window) {
for i in 1..100 {
std::thread::sleep(std::time::Duration::from_millis(150));
// emit a download progress event to the updater window
window.emit_filter("download-progress", i, |t| match t {
EventTarget::WebviewWindow { label } => label == "main",
_ => false,
});
}
}
Source§impl<R: Runtime> FunctionArg for Window<R>
impl<R: Runtime> FunctionArg for Window<R>
Source§impl<R: Runtime> HasDisplayHandle for Window<R>
impl<R: Runtime> HasDisplayHandle for Window<R>
Source§fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
Source§impl<R: Runtime> HasWindowHandle for Window<R>
impl<R: Runtime> HasWindowHandle for Window<R>
Source§fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
Source§impl<R: Runtime> Listener<R> for Window<R>
impl<R: Runtime> Listener<R> for Window<R>
Source§fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
Listen to an event on this window.
§Examples
use tauri::{Manager, Listener};
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();
window.listen("component-loaded", move |event| {
println!("window just loaded a component");
});
Ok(())
});
Source§fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
Listen to an event on this window only once.
See Self::listen
for more information.
Source§fn unlisten(&self, id: EventId)
fn unlisten(&self, id: EventId)
Unlisten to an event on this window.
§Examples
use tauri::{Manager, Listener};
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();
let window_ = window.clone();
let handler = window.listen("component-loaded", move |event| {
println!("window just loaded a component");
// we no longer need to listen to the event
// we also could have used `window.once` instead
window_.unlisten(event.id());
});
// stop listening to the event when you do not need it anymore
window.unlisten(handler);
Ok(())
});
Source§impl<R: Runtime> Manager<R> for Window<R>
impl<R: Runtime> Manager<R> for Window<R>
Source§fn resources_table(&self) -> MutexGuard<'_, ResourceTable>
fn resources_table(&self) -> MutexGuard<'_, ResourceTable>
Source§fn app_handle(&self) -> &AppHandle<R>
fn app_handle(&self) -> &AppHandle<R>
Source§fn package_info(&self) -> &PackageInfo
fn package_info(&self) -> &PackageInfo
PackageInfo
the manager was created with.Source§fn get_window(&self, label: &str) -> Option<Window<R>>
fn get_window(&self, label: &str) -> Option<Window<R>>
unstable
only.Source§fn get_focused_window(&self) -> Option<Window<R>>
fn get_focused_window(&self) -> Option<Window<R>>
unstable
only.None
if there is not any focused window.Source§fn windows(&self) -> HashMap<String, Window<R>>
fn windows(&self) -> HashMap<String, Window<R>>
unstable
only.Source§fn get_webview(&self, label: &str) -> Option<Webview<R>>
fn get_webview(&self, label: &str) -> Option<Webview<R>>
unstable
only.Source§fn webviews(&self) -> HashMap<String, Webview<R>>
fn webviews(&self) -> HashMap<String, Webview<R>>
unstable
only.Source§fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>
fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>
Source§fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>
fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>
Source§fn manage<T>(&self, state: T) -> bool
fn manage<T>(&self, state: T) -> bool
state
to the state managed by the application. Read moreSource§fn unmanage<T>(&self) -> Option<T>
fn unmanage<T>(&self) -> Option<T>
Source§fn try_state<T>(&self) -> Option<State<'_, T>>
fn try_state<T>(&self) -> Option<State<'_, T>>
T
. Read moreSource§fn asset_protocol_scope(&self) -> Scope
fn asset_protocol_scope(&self) -> Scope
Source§fn path(&self) -> &PathResolver<R>
fn path(&self) -> &PathResolver<R>
Source§fn add_capability(&self, capability: impl RuntimeCapability) -> Result<()>
fn add_capability(&self, capability: impl RuntimeCapability) -> Result<()>
impl<R: Runtime> Eq for Window<R>
Auto Trait Implementations§
impl<R> Freeze for Window<R>where
<R as Runtime<EventLoopMessage>>::WindowDispatcher: Freeze,
<R as Runtime<EventLoopMessage>>::Handle: Freeze,
<R as Runtime<EventLoopMessage>>::WebviewDispatcher: Freeze,
impl<R = Wry<EventLoopMessage>> !RefUnwindSafe for Window<R>
impl<R> Send for Window<R>
impl<R> Sync for Window<R>
impl<R> Unpin for Window<R>where
<R as Runtime<EventLoopMessage>>::WindowDispatcher: Unpin,
<R as Runtime<EventLoopMessage>>::Handle: Unpin,
<R as Runtime<EventLoopMessage>>::WebviewDispatcher: Unpin,
impl<R = Wry<EventLoopMessage>> !UnwindSafe for Window<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
Source§fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
HasDisplayHandle
insteadSource§impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
Source§fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
HasWindowHandle
instead