| | | 1 | | // SPDX-FileCopyrightText: 2026 Alper Çelik |
| | | 2 | | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| | | 3 | | |
| | | 4 | | //! Window declarations (owned by the window worker). |
| | | 5 | | //! |
| | | 6 | | //! C++ translation units include the cxx-generated header for this bridge: |
| | | 7 | | //! `#include "tauri-runtime-qt/src/bridge/window.rs.h"`. |
| | | 8 | | |
| | | 9 | | #[cxx::bridge] |
| | | 10 | | pub mod ffi { |
| | | 11 | | /// A size in Qt device-independent ("logical") pixels. |
| | | 12 | | struct QtWindowSize { |
| | | 13 | | width: f64, |
| | | 14 | | height: f64, |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | /// A point in Qt device-independent ("logical") pixels. |
| | | 18 | | struct QtWindowPoint { |
| | | 19 | | x: f64, |
| | | 20 | | y: f64, |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | unsafe extern "C++" { |
| | | 24 | | include!("qt_window.hpp"); |
| | | 25 | | |
| | | 26 | | // ---- windows (qt_window.cpp) ---- |
| | 20 | 27 | | fn qt_window_create( |
| | 20 | 28 | | label: &str, |
| | 20 | 29 | | title: &str, |
| | 20 | 30 | | width: i32, |
| | 20 | 31 | | height: i32, |
| | 20 | 32 | | visible: bool, |
| | 20 | 33 | | decorations: bool, |
| | 20 | 34 | | ) -> u64; |
| | 0 | 35 | | fn qt_window_show(id: u64); |
| | 0 | 36 | | fn qt_window_hide(id: u64); |
| | 0 | 37 | | fn qt_window_close(id: u64); |
| | 20 | 38 | | fn qt_window_set_title(id: u64, title: &str); |
| | 0 | 39 | | fn qt_window_set_size(id: u64, width: i32, height: i32); |
| | 0 | 40 | | fn qt_window_center(id: u64); |
| | 0 | 41 | | fn qt_window_set_decorations(id: u64, decorations: bool); |
| | 0 | 42 | | fn qt_window_set_maximized(id: u64, maximized: bool); |
| | 40 | 43 | | fn qt_window_is_visible(id: u64) -> bool; |
| | 200 | 44 | | fn qt_window_scale_factor(id: u64) -> f64; |
| | 0 | 45 | | fn qt_window_winid(id: u64) -> u64; |
| | 20 | 46 | | fn qt_window_attach_webview(window_id: u64, webview_native_id: u64); |
| | | 47 | | |
| | | 48 | | // ---- window worker: registry and platform ---- |
| | | 49 | | /// Whether `id` names a live window in the C++ registry. Rust answers |
| | | 50 | | /// `Error::WindowNotFound` when it does not, instead of guessing. |
| | 520 | 51 | | fn qt_window_alive(id: u64) -> bool; |
| | | 52 | | |
| | | 53 | | /// Name of the Qt platform plugin in use (e.g. `"xcb"`, `"wayland"`). |
| | 0 | 54 | | fn qt_window_platform() -> String; |
| | | 55 | | |
| | | 56 | | // ---- geometry (Qt logical pixels; Rust applies the scale factor) ---- |
| | | 57 | | /// Client area size (`QWidget::size()`). |
| | 40 | 58 | | fn qt_window_inner_size(id: u64) -> QtWindowSize; |
| | | 59 | | /// Frame size including window manager decorations |
| | | 60 | | /// (`QWidget::frameGeometry()`). |
| | 40 | 61 | | fn qt_window_outer_size(id: u64) -> QtWindowSize; |
| | | 62 | | /// Client area origin on the desktop (`QWidget::mapToGlobal(0, 0)`). |
| | 40 | 63 | | fn qt_window_inner_position(id: u64) -> QtWindowPoint; |
| | | 64 | | /// Frame origin on the desktop (`QWidget::frameGeometry().topLeft()`). |
| | 40 | 65 | | fn qt_window_outer_position(id: u64) -> QtWindowPoint; |
| | | 66 | | |
| | | 67 | | // ---- state ---- |
| | 40 | 68 | | fn qt_window_title(id: u64) -> String; |
| | | 69 | | /// `QStyleHints::colorScheme()`: 1 = light, 2 = dark, 0 = unknown. |
| | 0 | 70 | | fn qt_window_theme(id: u64) -> i32; |
| | 40 | 71 | | fn qt_window_is_fullscreen(id: u64) -> bool; |
| | 40 | 72 | | fn qt_window_is_minimized(id: u64) -> bool; |
| | 40 | 73 | | fn qt_window_is_maximized(id: u64) -> bool; |
| | 40 | 74 | | fn qt_window_is_focused(id: u64) -> bool; |
| | 40 | 75 | | fn qt_window_is_decorated(id: u64) -> bool; |
| | 40 | 76 | | fn qt_window_is_resizable(id: u64) -> bool; |
| | 0 | 77 | | fn qt_window_is_enabled(id: u64) -> bool; |
| | 40 | 78 | | fn qt_window_is_always_on_top(id: u64) -> bool; |
| | | 79 | | /// Qt's `WindowMaximizeButtonHint` / `WindowMinimizeButtonHint` / |
| | | 80 | | /// `WindowCloseButtonHint` bits (the hints handed to the window |
| | | 81 | | /// manager; Qt offers no per-button state beyond them). |
| | 0 | 82 | | fn qt_window_is_maximizable(id: u64) -> bool; |
| | 0 | 83 | | fn qt_window_is_minimizable(id: u64) -> bool; |
| | 0 | 84 | | fn qt_window_is_closable(id: u64) -> bool; |
| | | 85 | | |
| | | 86 | | // ---- setters ---- |
| | 40 | 87 | | fn qt_window_set_fullscreen(id: u64, fullscreen: bool); |
| | 0 | 88 | | fn qt_window_minimize(id: u64); |
| | 0 | 89 | | fn qt_window_unminimize(id: u64); |
| | | 90 | | /// Qt logical pixels; `0` / `QWIDGETSIZE_MAX` mean "no min/max". |
| | 0 | 91 | | fn qt_window_set_min_size(id: u64, width: f64, height: f64); |
| | 0 | 92 | | fn qt_window_set_max_size(id: u64, width: f64, height: f64); |
| | | 93 | | /// Takes the icon's straight RGBA8888 bytes. Returns false when the |
| | | 94 | | /// buffer does not match `width * height * 4` (Rust pre-validates too). |
| | 0 | 95 | | fn qt_window_set_icon(id: u64, rgba: &[u8], width: u32, height: u32) -> bool; |
| | 0 | 96 | | fn qt_window_set_focus(id: u64); |
| | 0 | 97 | | fn qt_window_set_resizable(id: u64, resizable: bool); |
| | 0 | 98 | | fn qt_window_set_enabled(id: u64, enabled: bool); |
| | 0 | 99 | | fn qt_window_set_always_on_top(id: u64, on_top: bool); |
| | 0 | 100 | | fn qt_window_set_always_on_bottom(id: u64, on_bottom: bool); |
| | 0 | 101 | | fn qt_window_set_background_color(id: u64, r: u8, g: u8, b: u8, a: u8); |
| | | 102 | | /// Restores the application palette (tauri's `None` background). |
| | 0 | 103 | | fn qt_window_reset_background_color(id: u64); |
| | | 104 | | /// Moves the frame origin (X11 only; Rust rejects other platforms). |
| | 0 | 105 | | fn qt_window_set_position(id: u64, x: i32, y: i32); |
| | | 106 | | /// Returns false when Qt cannot start the system move (no native |
| | | 107 | | /// window handle, or not called from a mouse press/release handler). |
| | 0 | 108 | | fn qt_window_start_dragging(id: u64) -> bool; |
| | | 109 | | /// `direction` is tauri's `ResizeDirection` number (1..8, as mapped by |
| | | 110 | | /// `lib.rs`); Qt maps it to `Qt::Edges`. Returns false when Qt cannot |
| | | 111 | | /// start the system resize or the direction is unknown. |
| | 0 | 112 | | fn qt_window_start_resize_dragging(id: u64, direction: i32) -> bool; |
| | | 113 | | } |
| | | 114 | | } |