Skip to content

Commit

Permalink
Windows: Amend transparency code
Browse files Browse the repository at this point in the history
  • Loading branch information
subnomo committed Oct 15, 2018
1 parent 4166063 commit c015b63
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use winapi::shared::windef::{HWND, LPPOINT, POINT, RECT};
use winapi::um::{combaseapi, dwmapi, libloaderapi, winuser};
use winapi::um::objbase::COINIT_MULTITHREADED;
use winapi::um::shobjidl_core::{CLSID_TaskbarList, ITaskbarList2};
use winapi::um::wingdi::{CreateRectRgn, DeleteObject};
use winapi::um::winnt::{LONG, LPCWSTR};
use winapi::um::wingdi::CreateRectRgn;

use {
CreationError,
Expand Down Expand Up @@ -1022,22 +1022,28 @@ unsafe fn init(

// making the window transparent
if attributes.transparent && !pl_attribs.no_redirection_bitmap {
let region = CreateRectRgn(0, 0, -1, -1); // makes the window transparent

let bb = dwmapi::DWM_BLURBEHIND {
dwFlags: dwmapi::DWM_BB_ENABLE | dwmapi::DWM_BB_BLURREGION,
fEnable: 1,
hRgnBlur: CreateRectRgn(0, 0, -1, -1), // makes the window transparent
hRgnBlur: region,
fTransitionOnMaximized: 0,
};

dwmapi::DwmEnableBlurBehindWindow(real_window.0, &bb);
DeleteObject(region as _);

if attributes.decorations {
// HACK: When opaque (opacity 255), there is a trail whenever
// the transparent window is moved. By reducing it to 254,
// the window is rendered properly.
let opacity = 254;

winuser::SetLayeredWindowAttributes(real_window.0, 0x0030c100, opacity, winuser::LWA_ALPHA);
// The color key can be any value except for black (0x0).
let color_key = 0x0030c100;

winuser::SetLayeredWindowAttributes(real_window.0, color_key, opacity, winuser::LWA_ALPHA);
}
}

Expand Down

0 comments on commit c015b63

Please sign in to comment.