Merge pull request #2189 from Calastrophe/master
Add functions to fetch if a window is maximized or minimized
This commit is contained in:
commit
90332acc4b
5 changed files with 70 additions and 1 deletions
|
|
@ -58,7 +58,7 @@ pub enum Event {
|
||||||
/// for each file separately.
|
/// for each file separately.
|
||||||
FileHovered(PathBuf),
|
FileHovered(PathBuf),
|
||||||
|
|
||||||
/// A file has beend dropped into the window.
|
/// A file has been dropped into the window.
|
||||||
///
|
///
|
||||||
/// When the user drops multiple files at once, this event will be emitted
|
/// When the user drops multiple files at once, this event will be emitted
|
||||||
/// for each file separately.
|
/// for each file separately.
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,33 @@ pub fn fetch_size<Message>(
|
||||||
Command::single(command::Action::Window(Action::FetchSize(id, Box::new(f))))
|
Command::single(command::Action::Window(Action::FetchSize(id, Box::new(f))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetches if the window is maximized.
|
||||||
|
pub fn fetch_maximized<Message>(
|
||||||
|
id: Id,
|
||||||
|
f: impl FnOnce(bool) -> Message + 'static,
|
||||||
|
) -> Command<Message> {
|
||||||
|
Command::single(command::Action::Window(Action::FetchMaximized(
|
||||||
|
id,
|
||||||
|
Box::new(f),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Maximizes the window.
|
/// Maximizes the window.
|
||||||
pub fn maximize<Message>(id: Id, maximized: bool) -> Command<Message> {
|
pub fn maximize<Message>(id: Id, maximized: bool) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::Maximize(id, maximized)))
|
Command::single(command::Action::Window(Action::Maximize(id, maximized)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetches if the window is minimized.
|
||||||
|
pub fn fetch_minimized<Message>(
|
||||||
|
id: Id,
|
||||||
|
f: impl FnOnce(Option<bool>) -> Message + 'static,
|
||||||
|
) -> Command<Message> {
|
||||||
|
Command::single(command::Action::Window(Action::FetchMinimized(
|
||||||
|
id,
|
||||||
|
Box::new(f),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Minimizes the window.
|
/// Minimizes the window.
|
||||||
pub fn minimize<Message>(id: Id, minimized: bool) -> Command<Message> {
|
pub fn minimize<Message>(id: Id, minimized: bool) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::Minimize(id, minimized)))
|
Command::single(command::Action::Window(Action::Minimize(id, minimized)))
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,19 @@ pub enum Action<T> {
|
||||||
Resize(Id, Size),
|
Resize(Id, Size),
|
||||||
/// Fetch the current logical dimensions of the window.
|
/// Fetch the current logical dimensions of the window.
|
||||||
FetchSize(Id, Box<dyn FnOnce(Size) -> T + 'static>),
|
FetchSize(Id, Box<dyn FnOnce(Size) -> T + 'static>),
|
||||||
|
/// Fetch if the current window is maximized or not.
|
||||||
|
///
|
||||||
|
/// ## Platform-specific
|
||||||
|
/// - **iOS / Android / Web:** Unsupported.
|
||||||
|
FetchMaximized(Id, Box<dyn FnOnce(bool) -> T + 'static>),
|
||||||
/// Set the window to maximized or back
|
/// Set the window to maximized or back
|
||||||
Maximize(Id, bool),
|
Maximize(Id, bool),
|
||||||
|
/// Fetch if the current window is minimized or not.
|
||||||
|
///
|
||||||
|
/// ## Platform-specific
|
||||||
|
/// - **Wayland:** Always `None`.
|
||||||
|
/// - **iOS / Android / Web:** Unsupported.
|
||||||
|
FetchMinimized(Id, Box<dyn FnOnce(Option<bool>) -> T + 'static>),
|
||||||
/// Set the window to minimized or back
|
/// Set the window to minimized or back
|
||||||
Minimize(Id, bool),
|
Minimize(Id, bool),
|
||||||
/// Move the window to the given logical coordinates.
|
/// Move the window to the given logical coordinates.
|
||||||
|
|
@ -106,7 +117,13 @@ impl<T> Action<T> {
|
||||||
Self::FetchSize(id, o) => {
|
Self::FetchSize(id, o) => {
|
||||||
Action::FetchSize(id, Box::new(move |s| f(o(s))))
|
Action::FetchSize(id, Box::new(move |s| f(o(s))))
|
||||||
}
|
}
|
||||||
|
Self::FetchMaximized(id, o) => {
|
||||||
|
Action::FetchMaximized(id, Box::new(move |s| f(o(s))))
|
||||||
|
}
|
||||||
Self::Maximize(id, maximized) => Action::Maximize(id, maximized),
|
Self::Maximize(id, maximized) => Action::Maximize(id, maximized),
|
||||||
|
Self::FetchMinimized(id, o) => {
|
||||||
|
Action::FetchMinimized(id, Box::new(move |s| f(o(s))))
|
||||||
|
}
|
||||||
Self::Minimize(id, minimized) => Action::Minimize(id, minimized),
|
Self::Minimize(id, minimized) => Action::Minimize(id, minimized),
|
||||||
Self::Move(id, position) => Action::Move(id, position),
|
Self::Move(id, position) => Action::Move(id, position),
|
||||||
Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode),
|
Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode),
|
||||||
|
|
@ -144,9 +161,15 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
write!(f, "Action::Resize({id:?}, {size:?})")
|
write!(f, "Action::Resize({id:?}, {size:?})")
|
||||||
}
|
}
|
||||||
Self::FetchSize(id, _) => write!(f, "Action::FetchSize({id:?})"),
|
Self::FetchSize(id, _) => write!(f, "Action::FetchSize({id:?})"),
|
||||||
|
Self::FetchMaximized(id, _) => {
|
||||||
|
write!(f, "Action::FetchMaximized({id:?})")
|
||||||
|
}
|
||||||
Self::Maximize(id, maximized) => {
|
Self::Maximize(id, maximized) => {
|
||||||
write!(f, "Action::Maximize({id:?}, {maximized})")
|
write!(f, "Action::Maximize({id:?}, {maximized})")
|
||||||
}
|
}
|
||||||
|
Self::FetchMinimized(id, _) => {
|
||||||
|
write!(f, "Action::FetchMinimized({id:?})")
|
||||||
|
}
|
||||||
Self::Minimize(id, minimized) => {
|
Self::Minimize(id, minimized) => {
|
||||||
write!(f, "Action::Minimize({id:?}, {minimized}")
|
write!(f, "Action::Minimize({id:?}, {minimized}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -742,9 +742,19 @@ pub fn run_command<A, C, E>(
|
||||||
)))
|
)))
|
||||||
.expect("Send message to event loop");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
|
window::Action::FetchMaximized(_id, callback) => {
|
||||||
|
proxy
|
||||||
|
.send_event(callback(window.is_maximized()))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
window::Action::Maximize(_id, maximized) => {
|
window::Action::Maximize(_id, maximized) => {
|
||||||
window.set_maximized(maximized);
|
window.set_maximized(maximized);
|
||||||
}
|
}
|
||||||
|
window::Action::FetchMinimized(_id, callback) => {
|
||||||
|
proxy
|
||||||
|
.send_event(callback(window.is_minimized()))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
window::Action::Minimize(_id, minimized) => {
|
window::Action::Minimize(_id, minimized) => {
|
||||||
window.set_minimized(minimized);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -942,11 +942,25 @@ fn run_command<A, C, E>(
|
||||||
.expect("Send message to event loop");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window::Action::FetchMaximized(id, callback) => {
|
||||||
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
|
proxy
|
||||||
|
.send_event(callback(window.raw.is_maximized()))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
}
|
||||||
window::Action::Maximize(id, maximized) => {
|
window::Action::Maximize(id, maximized) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
window.raw.set_maximized(maximized);
|
window.raw.set_maximized(maximized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window::Action::FetchMinimized(id, callback) => {
|
||||||
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
|
proxy
|
||||||
|
.send_event(callback(window.raw.is_minimized()))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
}
|
||||||
window::Action::Minimize(id, minimized) => {
|
window::Action::Minimize(id, minimized) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
window.raw.set_minimized(minimized);
|
window.raw.set_minimized(minimized);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue