Skip to content

Commit 2499e44

Browse files
committed
feat(ui): style title bar on windows
1 parent d64d52d commit 2499e44

4 files changed

Lines changed: 462 additions & 452 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,5 @@ tauri-plugin-window-state = "2"
8888
[target."cfg(target_os = \"macos\")".dependencies]
8989
objc2 = "0.6.2"
9090
objc2-app-kit = "0.3.1"
91+
[target."cfg(target_os = \"windows\")".dependencies]
92+
windows = { version = "0.61", features = ["Win32_Graphics_Dwm"] }

src-tauri/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,38 @@ pub fn run() {
747747
}
748748
}
749749

750+
// set title bar color only when building for Windows
751+
#[cfg(target_os = "windows")]
752+
{
753+
use windows::Win32::Foundation::COLORREF;
754+
use windows::Win32::Graphics::Dwm::{
755+
DwmSetWindowAttribute, DWMWA_CAPTION_COLOR,
756+
DWMWA_USE_IMMERSIVE_DARK_MODE,
757+
};
758+
759+
let hwnd = window.hwnd().unwrap();
760+
761+
unsafe {
762+
// enable dark mode for title bar text/buttons
763+
let use_dark_mode: i32 = 1;
764+
let _ = DwmSetWindowAttribute(
765+
hwnd,
766+
DWMWA_USE_IMMERSIVE_DARK_MODE,
767+
&use_dark_mode as *const i32 as *const std::ffi::c_void,
768+
std::mem::size_of::<i32>() as u32,
769+
);
770+
771+
// RGB(20, 26, 39) -> COLORREF 0x00BBGGRR = 0x00271A14
772+
let caption_color = COLORREF(0x00271A14);
773+
let _ = DwmSetWindowAttribute(
774+
hwnd,
775+
DWMWA_CAPTION_COLOR,
776+
&caption_color as *const COLORREF as *const std::ffi::c_void,
777+
std::mem::size_of::<COLORREF>() as u32,
778+
);
779+
}
780+
}
781+
750782
let client: HelixClient<'static, reqwest::Client> =
751783
twitch_api::HelixClient::with_client(
752784
ClientDefault::default_client_with_name(Some(

0 commit comments

Comments
 (0)