From 81314f91d82dff07f6da3409dd1280a68d4dcd60 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 15 May 2015 15:19:33 +0200 Subject: Add API for transparency and decorations and add support for win32 --- src/api/win32/callback.rs | 1 + src/api/win32/init.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/api/win32') diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index 1ea95a5..86d5f1c 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -44,6 +44,7 @@ fn send_event(input_window: winapi::HWND, event: Event) { /// This is the callback that is called by `DispatchMessage` in the events loop. /// /// Returning 0 tells the Win32 API that the message has been processed. +// FIXME: detect WM_DWMCOMPOSITIONCHANGED and call DwmEnableBlurBehindWindow if necessary pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> winapi::LRESULT diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs index fb4e181..1252354 100644 --- a/src/api/win32/init.rs +++ b/src/api/win32/init.rs @@ -102,7 +102,7 @@ unsafe fn init(title: Vec, builder: BuilderAttribs<'static>, } // computing the style and extended style of the window - let (ex_style, style) = if builder.monitor.is_some() { + let (ex_style, style) = if builder.monitor.is_some() || builder.decorations == false { (winapi::WS_EX_APPWINDOW, winapi::WS_POPUP | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN) } else { (winapi::WS_EX_APPWINDOW | winapi::WS_EX_WINDOWEDGE, @@ -214,6 +214,27 @@ unsafe fn init(title: Vec, builder: BuilderAttribs<'static>, } }; + // making the window transparent + if builder.transparent { + let bb = winapi::DWM_BLURBEHIND { + dwFlags: 0x1, // FIXME: DWM_BB_ENABLE; + fEnable: 1, + hRgnBlur: ptr::null_mut(), + fTransitionOnMaximized: 0, + }; + + let dll = kernel32::LoadLibraryA(b"dwmapi.dll\0".as_ptr() as *const _); + if !dll.is_null() { + let pr = kernel32::GetProcAddress(dll, b"DwmEnableBlurBehindWindow\0".as_ptr() as *const _); + if !pr.is_null() { + let pr: unsafe extern "system" fn(winapi::HWND, *const winapi::DWM_BLURBEHIND) + -> winapi::HRESULT = mem::transmute(pr); + pr(real_window.0, &bb); + } + kernel32::FreeLibrary(dll); + } + } + // calling SetForegroundWindow if fullscreen if builder.monitor.is_some() { user32::SetForegroundWindow(real_window.0); -- cgit v1.2.3 From 9117bcf3d3f441c86c85b04ce54e135d28fcb2e1 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 20 May 2015 18:46:10 +0200 Subject: Switch to dwmapi --- Cargo.toml | 6 ++++-- src/api/win32/init.rs | 12 +++--------- src/lib.rs | 2 ++ 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src/api/win32') diff --git a/Cargo.toml b/Cargo.toml index 4f73636..4bcbac5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,16 +37,18 @@ glutin_core_graphics = "0" glutin_core_foundation = "0" [target.i686-pc-windows-gnu.dependencies] -winapi = "0.1" +winapi = "~0.1.18" gdi32-sys = "0.1" user32-sys = "~0.1.1" kernel32-sys = "0.1" +dwmapi-sys = "0.1" [target.x86_64-pc-windows-gnu.dependencies] -winapi = "0.1" +winapi = "~0.1.18" gdi32-sys = "0.1" user32-sys = "~0.1.1" kernel32-sys = "0.1" +dwmapi-sys = "0.1" [target.i686-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs index 1252354..f46c395 100644 --- a/src/api/win32/init.rs +++ b/src/api/win32/init.rs @@ -25,6 +25,7 @@ use std::sync::mpsc::channel; use winapi; use kernel32; +use dwmapi; use user32; use api::wgl; @@ -223,15 +224,8 @@ unsafe fn init(title: Vec, builder: BuilderAttribs<'static>, fTransitionOnMaximized: 0, }; - let dll = kernel32::LoadLibraryA(b"dwmapi.dll\0".as_ptr() as *const _); - if !dll.is_null() { - let pr = kernel32::GetProcAddress(dll, b"DwmEnableBlurBehindWindow\0".as_ptr() as *const _); - if !pr.is_null() { - let pr: unsafe extern "system" fn(winapi::HWND, *const winapi::DWM_BLURBEHIND) - -> winapi::HRESULT = mem::transmute(pr); - pr(real_window.0, &bb); - } - kernel32::FreeLibrary(dll); + unsafe { + dwmapi::DwmEnableBlurBehindWindow(real_window.0, &bb); } } diff --git a/src/lib.rs b/src/lib.rs index d2aaf46..612206e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,8 @@ extern crate kernel32; extern crate gdi32; #[cfg(target_os = "windows")] extern crate user32; +#[cfg(target_os = "windows")] +extern crate dwmapi; #[cfg(target_os = "macos")] #[macro_use] extern crate objc; -- cgit v1.2.3