mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Add Window::title
getter on Windows and macOS
This commit is contained in:
parent
a7a7cc64cd
commit
08f9e374e0
|
@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On Windows and macOS, add `Window::title` to query the current window title.
|
||||||
- On Windows, fix focusing menubar when pressing `Alt`.
|
- On Windows, fix focusing menubar when pressing `Alt`.
|
||||||
- On MacOS, made `accepts_first_mouse` configurable.
|
- On MacOS, made `accepts_first_mouse` configurable.
|
||||||
- Migrated `WindowBuilderExtUnix::with_resize_increments` to `WindowBuilder`.
|
- Migrated `WindowBuilderExtUnix::with_resize_increments` to `WindowBuilder`.
|
||||||
|
|
|
@ -856,6 +856,10 @@ impl Window {
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
|
|
|
@ -347,6 +347,11 @@ impl Inner {
|
||||||
warn!("`Window::theme` is ignored on iOS");
|
warn!("`Window::theme` is ignored on iOS");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
warn!("`Window::title` is ignored on iOS");
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
|
|
|
@ -589,6 +589,11 @@ impl Window {
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
x11_or_wayland!(match self; Window(window) => window.theme())
|
x11_or_wayland!(match self; Window(window) => window.theme())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
x11_or_wayland!(match self; Window(window) => window.title())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hooks for X11 errors.
|
/// Hooks for X11 errors.
|
||||||
|
|
|
@ -624,6 +624,11 @@ impl Window {
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
|
|
|
@ -1551,4 +1551,9 @@ impl UnownedWindow {
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,10 @@ extern_methods!(
|
||||||
#[sel(setTitle:)]
|
#[sel(setTitle:)]
|
||||||
pub fn setTitle(&self, title: &NSString);
|
pub fn setTitle(&self, title: &NSString);
|
||||||
|
|
||||||
|
pub fn title_(&self) -> Id<NSString, Shared> {
|
||||||
|
unsafe { msg_send_id![self, title] }
|
||||||
|
}
|
||||||
|
|
||||||
#[sel(setReleasedWhenClosed:)]
|
#[sel(setReleasedWhenClosed:)]
|
||||||
pub fn setReleasedWhenClosed(&self, val: bool);
|
pub fn setReleasedWhenClosed(&self, val: bool);
|
||||||
|
|
||||||
|
|
|
@ -1115,6 +1115,11 @@ impl WinitWindow {
|
||||||
let state = self.shared_state.lock().unwrap();
|
let state = self.shared_state.lock().unwrap();
|
||||||
state.current_theme
|
state.current_theme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
self.title_().to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowExtMacOS for WinitWindow {
|
impl WindowExtMacOS for WinitWindow {
|
||||||
|
|
|
@ -378,6 +378,11 @@ impl Window {
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Window {
|
impl Drop for Window {
|
||||||
|
|
|
@ -40,13 +40,13 @@ use windows_sys::Win32::{
|
||||||
},
|
},
|
||||||
WindowsAndMessaging::{
|
WindowsAndMessaging::{
|
||||||
CreateWindowExW, FlashWindowEx, GetClientRect, GetCursorPos, GetForegroundWindow,
|
CreateWindowExW, FlashWindowEx, GetClientRect, GetCursorPos, GetForegroundWindow,
|
||||||
GetSystemMetrics, GetWindowPlacement, IsWindowVisible, LoadCursorW, PeekMessageW,
|
GetSystemMetrics, GetWindowPlacement, GetWindowTextLengthW, GetWindowTextW,
|
||||||
PostMessageW, RegisterClassExW, SetCursor, SetCursorPos, SetForegroundWindow,
|
IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor,
|
||||||
SetWindowPlacement, SetWindowPos, SetWindowTextW, CS_HREDRAW, CS_VREDRAW,
|
SetCursorPos, SetForegroundWindow, SetWindowPlacement, SetWindowPos, SetWindowTextW,
|
||||||
CW_USEDEFAULT, FLASHWINFO, FLASHW_ALL, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY,
|
CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, FLASHWINFO, FLASHW_ALL, FLASHW_STOP,
|
||||||
GWLP_HINSTANCE, HTCAPTION, MAPVK_VK_TO_VSC, NID_READY, PM_NOREMOVE, SM_DIGITIZER,
|
FLASHW_TIMERNOFG, FLASHW_TRAY, GWLP_HINSTANCE, HTCAPTION, MAPVK_VK_TO_VSC, NID_READY,
|
||||||
SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER, WM_NCLBUTTONDOWN,
|
PM_NOREMOVE, SM_DIGITIZER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE,
|
||||||
WNDCLASSEXW,
|
SWP_NOZORDER, WM_NCLBUTTONDOWN, WNDCLASSEXW,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -698,6 +698,14 @@ impl Window {
|
||||||
Some(self.window_state_lock().current_theme)
|
Some(self.window_state_lock().current_theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
let len = unsafe { GetWindowTextLengthW(self.window.0) } + 1;
|
||||||
|
let mut buf = vec![0; len as usize];
|
||||||
|
unsafe { GetWindowTextW(self.window.0, buf.as_mut_ptr(), len) };
|
||||||
|
util::decode_wide(&buf).to_string_lossy().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_skip_taskbar(&self, skip: bool) {
|
pub fn set_skip_taskbar(&self, skip: bool) {
|
||||||
self.window_state_lock().skip_taskbar = skip;
|
self.window_state_lock().skip_taskbar = skip;
|
||||||
|
|
|
@ -952,6 +952,16 @@ impl Window {
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
self.window.theme()
|
self.window.theme()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the current title of the window.
|
||||||
|
///
|
||||||
|
/// ## Platform-specific
|
||||||
|
///
|
||||||
|
/// - **iOS / Android / x11 / Wayland / Web:** Unsupported. Always returns an empty string.
|
||||||
|
#[inline]
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
self.window.title()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cursor functions.
|
/// Cursor functions.
|
||||||
|
|
Loading…
Reference in a new issue