first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -2,7 +2,8 @@ use std::ops::Not;
|
||||
|
||||
use arboard::{self, Clipboard as WindowsClipboardInner};
|
||||
|
||||
use crate::{clipboard::ClipboardContent, Clipboard};
|
||||
use crate::clipboard::ClipboardContent;
|
||||
use crate::Clipboard;
|
||||
|
||||
pub struct WindowsClipboard {
|
||||
inner: WindowsClipboardInner,
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
/// to avoid duplication. These tests focus on Windows-specific clipboard behavior.
|
||||
#[cfg(target_os = "windows")]
|
||||
mod clipboard_tests {
|
||||
use crate::clipboard::ClipboardContent;
|
||||
use crate::windowing::winit::windows::clipboard::WindowsClipboard;
|
||||
use crate::{clipboard::ClipboardContent, Clipboard};
|
||||
use crate::Clipboard;
|
||||
|
||||
fn create_test_clipboard() -> Option<WindowsClipboard> {
|
||||
WindowsClipboard::new().ok()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::windowing::winit::app::CustomEvent;
|
||||
use anyhow::Context;
|
||||
use windows::core::{implement, Interface};
|
||||
use windows::Win32::Networking::NetworkListManager::{
|
||||
@@ -11,6 +10,8 @@ use windows::Win32::System::Com::{
|
||||
COINIT_APARTMENTTHREADED,
|
||||
};
|
||||
|
||||
use crate::windowing::winit::app::CustomEvent;
|
||||
|
||||
/// Implements the INetworkListManagerEvents trait so we can pass along connectivity events from Windows
|
||||
/// OS to our winit event loop.
|
||||
#[implement(INetworkListManagerEvents)]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::platform::SystemTheme;
|
||||
use winreg::enums::HKEY_CURRENT_USER;
|
||||
use winreg::RegKey;
|
||||
|
||||
use crate::platform::SystemTheme;
|
||||
|
||||
const SYSTEM_THEME_SUBKEY_PATH: &str =
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
|
||||
const LIGHT_MODE_SUBKEY_NAME: &str = "AppsUseLightTheme";
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use super::window_attribute::get_window_attribute;
|
||||
use super::WindowAttributeErr;
|
||||
use windows::Win32::Foundation::RECT;
|
||||
use windows::Win32::Graphics::Dwm;
|
||||
use winit::window::Window as WinitWindow;
|
||||
|
||||
use super::window_attribute::get_window_attribute;
|
||||
use super::WindowAttributeErr;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SystemCaptionButtonData {
|
||||
bounds: RECT,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use std::{ffi::c_void, mem::size_of};
|
||||
use std::ffi::c_void;
|
||||
use std::mem::size_of;
|
||||
|
||||
use thiserror::Error;
|
||||
use wgpu::rwh;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Graphics::Dwm::{self, DWMWINDOWATTRIBUTE};
|
||||
use winit::raw_window_handle::HasWindowHandle;
|
||||
use winit::raw_window_handle::RawWindowHandle;
|
||||
use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle};
|
||||
use winit::window::Window as WinitWindow;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use windows::Win32::Foundation::{FALSE, HWND, TRUE};
|
||||
use windows::Win32::Foundation::{COLORREF, FALSE, HWND, TRUE};
|
||||
use windows::Win32::Graphics::Dwm::{DwmSetWindowAttribute, DWMWA_CLOAK};
|
||||
use windows::Win32::UI::WindowsAndMessaging::{
|
||||
GetWindowLongPtrW, SetLayeredWindowAttributes, SetWindowLongPtrW, GWL_EXSTYLE, LWA_ALPHA,
|
||||
WS_EX_LAYERED,
|
||||
};
|
||||
use windows_core::BOOL;
|
||||
use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle};
|
||||
use winit::window::Window;
|
||||
@@ -16,6 +20,13 @@ pub enum Error {
|
||||
pub trait WindowExt {
|
||||
/// "Cloaks" the window. A cloaked window is one that is invisible, but can still be drawn to.
|
||||
fn set_cloaked(&self, cloaked: bool) -> Result<(), Error>;
|
||||
|
||||
/// Sets the window's uniform opacity (`0.0` fully transparent, `1.0` fully
|
||||
/// opaque) using a layered window. Unlike `set_cloaked` or hiding, this keeps
|
||||
/// the window in the z-order and does not change focus, which is what the
|
||||
/// cross-window tab-drag preview relies on while hovering over a target
|
||||
/// window's tab bar.
|
||||
fn set_alpha(&self, alpha: f32) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl WindowExt for Window {
|
||||
@@ -39,4 +50,32 @@ impl WindowExt for Window {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_alpha(&self, alpha: f32) -> Result<(), Error> {
|
||||
let Ok(RawWindowHandle::Win32(handle)) = self
|
||||
.window_handle()
|
||||
.map(|window_handle| window_handle.as_raw())
|
||||
else {
|
||||
return Err(Error::InvalidWindowHandle);
|
||||
};
|
||||
|
||||
let hwnd = HWND(handle.hwnd.get() as _);
|
||||
let alpha_byte = (alpha.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||
|
||||
// SAFETY: `hwnd` is a valid top-level window handle obtained from winit.
|
||||
// `SetLayeredWindowAttributes` requires the `WS_EX_LAYERED` extended
|
||||
// style, so add it if it isn't already present. We intentionally leave
|
||||
// the style set afterwards: a fully-opaque (alpha 255) layered window
|
||||
// composites identically on DWM, which avoids the repaint quirks of
|
||||
// toggling the style off when restoring opacity.
|
||||
unsafe {
|
||||
let ex_style = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
|
||||
if ex_style & (WS_EX_LAYERED.0 as isize) == 0 {
|
||||
SetWindowLongPtrW(hwnd, GWL_EXSTYLE, ex_style | (WS_EX_LAYERED.0 as isize));
|
||||
}
|
||||
SetLayeredWindowAttributes(hwnd, COLORREF(0), alpha_byte, LWA_ALPHA)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user