| | | 1 | | // SPDX-FileCopyrightText: 2026 Alper Çelik |
| | | 2 | | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| | | 3 | | |
| | | 4 | | //! Screen/monitor/cursor declarations (owned by the screen worker). |
| | | 5 | | //! |
| | | 6 | | //! Implemented in `qt_screen.cpp`; C++ translation units include the |
| | | 7 | | //! cxx-generated header for this bridge: |
| | | 8 | | //! `#include "tauri-runtime-qt/src/bridge/screen.rs.h"`. |
| | | 9 | | //! |
| | | 10 | | //! Every geometry value that crosses this bridge is in Qt's device-independent |
| | | 11 | | //! (logical) global pixels, exactly as `QScreen::geometry()` and |
| | | 12 | | //! `QGuiApplication::screenAt()` express them; the `scale_factor` converts to |
| | | 13 | | //! physical pixels and is applied on the Rust side. |
| | | 14 | | |
| | | 15 | | #[cxx::bridge] |
| | | 16 | | pub mod ffi { |
| | | 17 | | /// One `QScreen`. |
| | | 18 | | struct QtScreenInfo { |
| | | 19 | | /// false for the placeholder value the lookups return when no screen |
| | | 20 | | /// matches; the other fields are then zeroed/empty. |
| | | 21 | | valid: bool, |
| | | 22 | | /// `QScreen::name()`; empty when the platform does not name the screen. |
| | | 23 | | name: String, |
| | | 24 | | /// `QScreen::geometry()`, logical global pixels. |
| | | 25 | | x: i32, |
| | | 26 | | y: i32, |
| | | 27 | | width: i32, |
| | | 28 | | height: i32, |
| | | 29 | | /// `QScreen::availableGeometry()`, logical global pixels. |
| | | 30 | | available_x: i32, |
| | | 31 | | available_y: i32, |
| | | 32 | | available_width: i32, |
| | | 33 | | available_height: i32, |
| | | 34 | | /// `QScreen::devicePixelRatio()`. |
| | | 35 | | scale_factor: f64, |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// `qt_screen_for_window()`: does the handle name a live window, and which |
| | | 39 | | /// screen is that window on? |
| | | 40 | | struct QtWindowScreen { |
| | | 41 | | /// false when `native` is not a handle this runtime created. |
| | | 42 | | window_known: bool, |
| | | 43 | | screen: QtScreenInfo, |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// `QCursor::pos()`: logical global position plus the scale factor of the |
| | | 47 | | /// screen under the cursor. |
| | | 48 | | struct QtCursorInfo { |
| | | 49 | | /// false when this platform cannot report a global cursor position. |
| | | 50 | | available: bool, |
| | | 51 | | x: f64, |
| | | 52 | | y: f64, |
| | | 53 | | scale_factor: f64, |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | unsafe extern "C++" { |
| | | 57 | | include!("qt_screen.hpp"); |
| | | 58 | | |
| | | 59 | | /// Whether a live `QGuiApplication` exists; monitors are unknowable |
| | | 60 | | /// before one does. |
| | 63 | 61 | | fn qt_screen_application_ready() -> bool; |
| | | 62 | | |
| | | 63 | | /// Every screen, in `QGuiApplication::screens()` order. |
| | 21 | 64 | | fn qt_screen_monitors() -> Vec<QtScreenInfo>; |
| | | 65 | | |
| | | 66 | | /// `QGuiApplication::primaryScreen()`; `valid == false` when there is |
| | | 67 | | /// no primary screen. |
| | 21 | 68 | | fn qt_screen_primary() -> QtScreenInfo; |
| | | 69 | | |
| | | 70 | | /// `QGuiApplication::screenAt()` for a logical global point; |
| | | 71 | | /// `valid == false` when no screen contains it. |
| | 0 | 72 | | fn qt_screen_at_point(x: f64, y: f64) -> QtScreenInfo; |
| | | 73 | | |
| | | 74 | | /// Screen of the window behind the runtime handle `native` (the screen |
| | | 75 | | /// containing the window, read through `QWidget::windowHandle()`). |
| | 21 | 76 | | fn qt_screen_for_window(native: u64) -> QtWindowScreen; |
| | | 77 | | |
| | | 78 | | /// `QCursor::pos()` in logical global coordinates. |
| | 0 | 79 | | fn qt_screen_cursor_position() -> QtCursorInfo; |
| | | 80 | | } |
| | | 81 | | } |