Skip to content

Commit

Permalink
feat(windows): allow setting window class name, closes #769 (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
geraudloup committed Jul 28, 2023
1 parent b31cb69 commit 75eb0c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-window-class-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

Add `WindowBuilderExtWindows::with_window_classname` to set the name of the window class created/used to create windows.
9 changes: 9 additions & 0 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ pub trait WindowBuilderExtWindows {
/// Whether to create the window icon with the taskbar icon or not.
fn with_skip_taskbar(self, skip: bool) -> WindowBuilder;

/// Customize the window class name.
fn with_window_classname<S: Into<String>>(self, classname: S) -> WindowBuilder;

/// Shows or hides the background drop shadow for undecorated windows.
///
/// The shadow is hidden by default.
Expand Down Expand Up @@ -284,6 +287,12 @@ impl WindowBuilderExtWindows for WindowBuilder {
self
}

#[inline]
fn with_window_classname<S: Into<String>>(mut self, classname: S) -> WindowBuilder {
self.platform_specific.window_classname = classname.into();
self
}

#[inline]
fn with_undecorated_shadow(mut self, shadow: bool) -> WindowBuilder {
self.platform_specific.decoration_shadow = shadow;
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub menu: Option<HMENU>,
pub taskbar_icon: Option<Icon>,
pub skip_taskbar: bool,
pub window_classname: String,
pub no_redirection_bitmap: bool,
pub drag_and_drop: bool,
pub preferred_theme: Option<Theme>,
Expand All @@ -64,6 +65,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
drag_and_drop: true,
preferred_theme: None,
skip_taskbar: false,
window_classname: "Window Class".to_string(),
decoration_shadow: true,
rtl: false,
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ unsafe fn init<T: 'static>(
event_loop: &EventLoopWindowTarget<T>,
) -> Result<Window, RootOsError> {
// registering the window class
let class_name = register_window_class();
let class_name = register_window_class(&pl_attribs.window_classname);

let mut window_flags = WindowFlags::empty();
window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations);
Expand Down Expand Up @@ -1180,8 +1180,8 @@ unsafe fn init<T: 'static>(
Ok(win)
}

unsafe fn register_window_class() -> Vec<u16> {
let class_name = util::encode_wide("Window Class");
unsafe fn register_window_class(window_classname: &str) -> Vec<u16> {
let class_name = util::encode_wide(window_classname);

let class = WNDCLASSEXW {
cbSize: mem::size_of::<WNDCLASSEXW>() as u32,
Expand Down

0 comments on commit 75eb0c1

Please sign in to comment.