Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functions/requests for changing icon #511

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ fn native_display() -> &'static Mutex<native::NativeDisplayData> {
/// Window and associated to window rendering context related functions.
/// in macroquad <= 0.3, it was ctx.screen_size(). Now it is window::screen_size()
pub mod window {
use conf::Icon;

use super::*;

/// The same as
Expand Down Expand Up @@ -251,6 +253,13 @@ pub mod window {
.unwrap();
}

pub fn set_window_icon(new_icon: Icon) {
let d = native_display().lock().unwrap();
d.native_requests
.send(native::Request::SetWindowIcon { new_icon })
.unwrap();
}

/// Get the position of the window.
/// TODO: implement for other platforms
#[cfg(any(target_os = "windows", target_os = "linux"))]
Expand Down
3 changes: 3 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(crate) enum Request {
SetMouseCursor(crate::CursorIcon),
SetWindowSize { new_width: u32, new_height: u32 },
SetWindowPosition { new_x: u32, new_y: u32 },
SetWindowIcon {new_icon: Icon},
SetFullscreen(bool),
ShowKeyboard(bool),
}
Expand Down Expand Up @@ -118,4 +119,6 @@ pub mod gl;
#[cfg(target_arch = "wasm32")]
pub use wasm::webgl as gl;

use crate::conf::Icon;

pub mod query_stab;
4 changes: 4 additions & 0 deletions src/native/linux_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
(self.libx11.XMoveWindow)(self.display, window, new_x, new_y);
}


fn show_mouse(&mut self, shown: bool) {
unsafe {
if shown {
Expand Down Expand Up @@ -358,6 +359,9 @@
SetWindowPosition { new_x, new_y } => {
self.set_window_position(self.window, new_x as _, new_y as _)
}
SetWindowIcon { new_icon } => {

Check warning on line 362 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `new_icon`

Check warning on line 362 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

unused variable: `new_icon`

Check warning on line 362 in src/native/linux_x11.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

unused variable: `new_icon`
eprintln!("Not implemented for X11")
}
SetFullscreen(fullscreen) => self.set_fullscreen(self.window, fullscreen),
ShowKeyboard(..) => {
eprintln!("Not implemented for X11")
Expand Down
1 change: 1 addition & 0 deletions src/native/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl MacosDisplay {
SetWindowPosition { .. } => {
eprintln!("Not implemented for macos");
}
SetWindowIcon {new_icon} => unsafe { set_icon(self.window, &new_icon) },
_ => {}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/native/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
unsafe {
#[cfg(target_arch = "x86_64")]
SetWindowLongPtrA(self.wnd, GWL_STYLE, win_style as _);
#[cfg(target_arch = "i686")]

Check warning on line 163 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition value: `i686`

Check warning on line 163 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition value: `i686`
SetWindowLong(self.wnd, GWL_STYLE, win_style as _);

if self.fullscreen {
Expand Down Expand Up @@ -837,8 +837,9 @@
new_height,
} => self.set_window_size(new_width as _, new_height as _),
SetWindowPosition { new_x, new_y } => self.set_window_position(new_x, new_y),
SetWindowIcon { new_icon } => set_icon(self.wnd, &new_icon),
SetFullscreen(fullscreen) => self.set_fullscreen(fullscreen),
ShowKeyboard(show) => {

Check warning on line 842 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unused variable: `show`

Check warning on line 842 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unused variable: `show`
eprintln!("Not implemented for windows")
}
}
Expand Down Expand Up @@ -917,7 +918,7 @@

#[cfg(target_arch = "x86_64")]
SetWindowLongPtrA(wnd, GWLP_USERDATA, &mut display as *mut _ as isize);
#[cfg(target_arch = "i686")]

Check warning on line 921 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition value: `i686`

Check warning on line 921 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition value: `i686`
SetWindowLong(wnd, GWLP_USERDATA, &mut display as *mut _ as isize);

let mut done = false;
Expand Down
Loading