Skip to content

Commit

Permalink
fix(deps): update rust crate windows-sys to 0.52.0 (#110)
Browse files Browse the repository at this point in the history
* fix(deps): update rust crate windows-sys to 0.52.0

* fix build

* Update Cargo.toml

* Create windwos-sys-0-52.md

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: amrbashir <amr.bashir2015@gmail.com>
  • Loading branch information
renovate[bot] and amrbashir committed Nov 16, 2023
1 parent 451d9ff commit 49587a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changes/windwos-sys-0-52.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"window-vibrancy": patch
---

Update `windows-sys` crate to 0.52
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ raw-window-handle = "0.5"
tao = "0.23"
winit = {version = "0.29", default-features = false, features = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita", "rwh_05"] }

[target."cfg(target_os = \"windows\")".dependencies]
windows-version = "0.1"

[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.48.0"
version = "0.52.0"
features = [
"Win32_Foundation",
"Win32_System_LibraryLoader",
Expand Down
66 changes: 19 additions & 47 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn apply_acrylic(hwnd: HWND, color: Option<Color>) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_SYSTEMBACKDROP_TYPE as _,
&DWM_SYSTEMBACKDROP_TYPE::DWMSBT_TRANSIENTWINDOW as *const _ as _,
4,
);
Expand All @@ -93,7 +93,7 @@ pub fn clear_acrylic(hwnd: HWND) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_SYSTEMBACKDROP_TYPE as _,
&DWM_SYSTEMBACKDROP_TYPE::DWMSBT_DISABLE as *const _ as _,
4,
);
Expand All @@ -115,7 +115,7 @@ pub fn apply_mica(hwnd: HWND, dark: Option<bool>) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_USE_IMMERSIVE_DARK_MODE,
DWMWA_USE_IMMERSIVE_DARK_MODE as _,
&(dark as u32) as *const _ as _,
4,
);
Expand All @@ -126,14 +126,14 @@ pub fn apply_mica(hwnd: HWND, dark: Option<bool>) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_SYSTEMBACKDROP_TYPE as _,
&DWM_SYSTEMBACKDROP_TYPE::DWMSBT_MAINWINDOW as *const _ as _,
4,
);
}
} else if is_undocumented_mica_supported() {
unsafe {
DwmSetWindowAttribute(hwnd, DWMWA_MICA_EFFECT, &1 as *const _ as _, 4);
DwmSetWindowAttribute(hwnd, DWMWA_MICA_EFFECT as _, &1 as *const _ as _, 4);
}
} else {
return Err(Error::UnsupportedPlatformVersion(
Expand All @@ -148,14 +148,14 @@ pub fn clear_mica(hwnd: HWND) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_SYSTEMBACKDROP_TYPE as _,
&DWM_SYSTEMBACKDROP_TYPE::DWMSBT_DISABLE as *const _ as _,
4,
);
}
} else if is_undocumented_mica_supported() {
unsafe {
DwmSetWindowAttribute(hwnd, DWMWA_MICA_EFFECT, &0 as *const _ as _, 4);
DwmSetWindowAttribute(hwnd, DWMWA_MICA_EFFECT as _, &0 as *const _ as _, 4);
}
} else {
return Err(Error::UnsupportedPlatformVersion(
Expand All @@ -170,7 +170,7 @@ pub fn apply_tabbed(hwnd: HWND, dark: Option<bool>) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_USE_IMMERSIVE_DARK_MODE,
DWMWA_USE_IMMERSIVE_DARK_MODE as _,
&(dark as u32) as *const _ as _,
4,
);
Expand All @@ -181,7 +181,7 @@ pub fn apply_tabbed(hwnd: HWND, dark: Option<bool>) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_SYSTEMBACKDROP_TYPE as _,
&DWM_SYSTEMBACKDROP_TYPE::DWMSBT_TABBEDWINDOW as *const _ as _,
4,
);
Expand All @@ -199,7 +199,7 @@ pub fn clear_tabbed(hwnd: HWND) -> Result<(), Error> {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
DWMWA_SYSTEMBACKDROP_TYPE as _,
&DWM_SYSTEMBACKDROP_TYPE::DWMSBT_DISABLE as *const _ as _,
4,
);
Expand Down Expand Up @@ -230,34 +230,6 @@ macro_rules! get_function {
};
}

/// Returns a tuple of (major, minor, buildnumber)
fn get_windows_ver() -> Option<(u32, u32, u32)> {
type RtlGetVersion = unsafe extern "system" fn(*mut OSVERSIONINFOW) -> i32;
let handle = unsafe { get_function!("ntdll.dll", RtlGetVersion) };
if let Some(rtl_get_version) = handle {
unsafe {
let mut vi = OSVERSIONINFOW {
dwOSVersionInfoSize: 0,
dwMajorVersion: 0,
dwMinorVersion: 0,
dwBuildNumber: 0,
dwPlatformId: 0,
szCSDVersion: [0; 128],
};

let status = (rtl_get_version)(&mut vi as _);

if status >= 0 {
Some((vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber))
} else {
None
}
}
} else {
None
}
}

#[repr(C)]
struct ACCENT_POLICY {
AccentState: u32,
Expand Down Expand Up @@ -322,8 +294,8 @@ unsafe fn SetWindowCompositionAttribute(
}
}

const DWMWA_MICA_EFFECT: DWMWINDOWATTRIBUTE = 1029i32;
const DWMWA_SYSTEMBACKDROP_TYPE: DWMWINDOWATTRIBUTE = 38i32;
const DWMWA_MICA_EFFECT: DWMWINDOWATTRIBUTE = 1029;
const DWMWA_SYSTEMBACKDROP_TYPE: DWMWINDOWATTRIBUTE = 38;

#[allow(unused)]
#[repr(C)]
Expand All @@ -335,8 +307,13 @@ enum DWM_SYSTEMBACKDROP_TYPE {
}

fn is_win7() -> bool {
let v = get_windows_ver().unwrap_or_default();
v.0 == 6 && v.1 == 1
let v = windows_version::OsVersion::current();
v.major == 6 && v.minor == 1
}

fn is_at_least_build(build: u32) -> bool {
let v = windows_version::OsVersion::current();
v.build >= build
}

fn is_swca_supported() -> bool {
Expand All @@ -350,8 +327,3 @@ fn is_undocumented_mica_supported() -> bool {
fn is_backdroptype_supported() -> bool {
is_at_least_build(22523)
}

fn is_at_least_build(build: u32) -> bool {
let v = get_windows_ver().unwrap_or_default();
v.2 >= build
}

0 comments on commit 49587a7

Please sign in to comment.