mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +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
|
||||
|
||||
- On Windows and macOS, add `Window::title` to query the current window title.
|
||||
- On Windows, fix focusing menubar when pressing `Alt`.
|
||||
- On MacOS, made `accepts_first_mouse` configurable.
|
||||
- Migrated `WindowBuilderExtUnix::with_resize_increments` to `WindowBuilder`.
|
||||
|
|
|
@ -856,6 +856,10 @@ impl Window {
|
|||
pub fn theme(&self) -> Option<Theme> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn title(&self) -> String {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
|
|
|
@ -347,6 +347,11 @@ impl Inner {
|
|||
warn!("`Window::theme` is ignored on iOS");
|
||||
None
|
||||
}
|
||||
|
||||
pub fn title(&self) -> String {
|
||||
warn!("`Window::title` is ignored on iOS");
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Window {
|
||||
|
|
|
@ -589,6 +589,11 @@ impl Window {
|
|||
pub fn theme(&self) -> Option<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.
|
||||
|
|
|
@ -624,6 +624,11 @@ impl Window {
|
|||
pub fn theme(&self) -> Option<Theme> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn title(&self) -> String {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Window {
|
||||
|
|
|
@ -1551,4 +1551,9 @@ impl UnownedWindow {
|
|||
pub fn theme(&self) -> Option<Theme> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn title(&self) -> String {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,6 +143,10 @@ extern_methods!(
|
|||
#[sel(setTitle:)]
|
||||
pub fn setTitle(&self, title: &NSString);
|
||||
|
||||
pub fn title_(&self) -> Id<NSString, Shared> {
|
||||
unsafe { msg_send_id![self, title] }
|
||||
}
|
||||
|
||||
#[sel(setReleasedWhenClosed:)]
|
||||
pub fn setReleasedWhenClosed(&self, val: bool);
|
||||
|
||||
|
|
|
@ -1115,6 +1115,11 @@ impl WinitWindow {
|
|||
let state = self.shared_state.lock().unwrap();
|
||||
state.current_theme
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn title(&self) -> String {
|
||||
self.title_().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowExtMacOS for WinitWindow {
|
||||
|
|
|
@ -378,6 +378,11 @@ impl Window {
|
|||
pub fn theme(&self) -> Option<Theme> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn title(&self) -> String {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Window {
|
||||
|
|
|
@ -40,13 +40,13 @@ use windows_sys::Win32::{
|
|||
},
|
||||
WindowsAndMessaging::{
|
||||
CreateWindowExW, FlashWindowEx, GetClientRect, GetCursorPos, GetForegroundWindow,
|
||||
GetSystemMetrics, GetWindowPlacement, IsWindowVisible, LoadCursorW, PeekMessageW,
|
||||
PostMessageW, RegisterClassExW, SetCursor, SetCursorPos, SetForegroundWindow,
|
||||
SetWindowPlacement, SetWindowPos, SetWindowTextW, CS_HREDRAW, CS_VREDRAW,
|
||||
CW_USEDEFAULT, FLASHWINFO, FLASHW_ALL, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY,
|
||||
GWLP_HINSTANCE, HTCAPTION, MAPVK_VK_TO_VSC, NID_READY, PM_NOREMOVE, SM_DIGITIZER,
|
||||
SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE, SWP_NOZORDER, WM_NCLBUTTONDOWN,
|
||||
WNDCLASSEXW,
|
||||
GetSystemMetrics, GetWindowPlacement, GetWindowTextLengthW, GetWindowTextW,
|
||||
IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor,
|
||||
SetCursorPos, SetForegroundWindow, SetWindowPlacement, SetWindowPos, SetWindowTextW,
|
||||
CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, FLASHWINFO, FLASHW_ALL, FLASHW_STOP,
|
||||
FLASHW_TIMERNOFG, FLASHW_TRAY, GWLP_HINSTANCE, HTCAPTION, MAPVK_VK_TO_VSC, NID_READY,
|
||||
PM_NOREMOVE, SM_DIGITIZER, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOSIZE,
|
||||
SWP_NOZORDER, WM_NCLBUTTONDOWN, WNDCLASSEXW,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -698,6 +698,14 @@ impl Window {
|
|||
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]
|
||||
pub fn set_skip_taskbar(&self, skip: bool) {
|
||||
self.window_state_lock().skip_taskbar = skip;
|
||||
|
|
|
@ -952,6 +952,16 @@ impl Window {
|
|||
pub fn theme(&self) -> Option<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.
|
||||
|
|
Loading…
Reference in a new issue