From 31fcf4ea83d998d78615bedfbdaa3da094f3731c Mon Sep 17 00:00:00 2001 From: cast1e Date: Wed, 16 Oct 2024 17:26:41 +0800 Subject: [PATCH] check miximized --- wallitor-core/dllmain.cpp | 4 +++ wallitor-core/playerInstance.cpp | 10 ++++++ wallitor-core/playerInstance.h | 3 +- wallitor-gui/src-tauri/src/handler/apply.rs | 36 +++++++++++++++++++-- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/wallitor-core/dllmain.cpp b/wallitor-core/dllmain.cpp index b5c53bb..96df458 100644 --- a/wallitor-core/dllmain.cpp +++ b/wallitor-core/dllmain.cpp @@ -33,3 +33,7 @@ playerInstance* player_instance = NULL; extern "C" __declspec(dllexport) BOOL set_wallpaper(const char* window_title) { return set_as_wallpaper(window_title); } + + extern "C" __declspec(dllexport) BOOL anyMaximized() { + return !detectWindowMaximized(); + } \ No newline at end of file diff --git a/wallitor-core/playerInstance.cpp b/wallitor-core/playerInstance.cpp index e421cc3..926ad93 100644 --- a/wallitor-core/playerInstance.cpp +++ b/wallitor-core/playerInstance.cpp @@ -86,4 +86,14 @@ BOOL set_as_wallpaper(const char* window_title) { SetParent(player, hProgman);// 将视频窗口设苦为PM的子窗口 EnumWindows(EnumWindowsProc, 0);// 找到第二个workerw窗口并隐藏它 return TRUE; +} + +static BOOL CALLBACK CheckMaximized(_In_ HWND hwnd, _In_ LPARAM Lparam) { + BOOL isMaximized = IsZoomed(hwnd); + if (isMaximized) return FALSE; + else return TRUE; +} + +BOOL detectWindowMaximized() { + return EnumWindows(CheckMaximized, 0); } \ No newline at end of file diff --git a/wallitor-core/playerInstance.h b/wallitor-core/playerInstance.h index 5595f96..077bdf4 100644 --- a/wallitor-core/playerInstance.h +++ b/wallitor-core/playerInstance.h @@ -13,4 +13,5 @@ public: void exit(); }; -BOOL set_as_wallpaper(const char* window_title); \ No newline at end of file +BOOL set_as_wallpaper(const char* window_title); +BOOL detectWindowMaximized(); \ No newline at end of file diff --git a/wallitor-gui/src-tauri/src/handler/apply.rs b/wallitor-gui/src-tauri/src/handler/apply.rs index 97b4272..f073398 100644 --- a/wallitor-gui/src-tauri/src/handler/apply.rs +++ b/wallitor-gui/src-tauri/src/handler/apply.rs @@ -1,5 +1,30 @@ -use std::ffi::CString; use libloading::{Library, Symbol}; +use std::{ffi::CString, rc::Rc, sync::Arc}; + +struct CoreModule<'a>{ + module:Arc, + set_wallpaper:Arc i8>>, + any_maximized:Arc i8>> +} + +impl<'a> CoreModule<'a> { + fn new(library_path: &str) -> Result { + let lib = Arc::new(unsafe { Library::new(library_path).unwrap() }); + + let set_fn:&Symbol<'a,unsafe extern "C" fn(*const i8) -> i8> = unsafe { + &lib.get:: i8>(b"set_wallpaper\0")? + }; + let any_fn:&Symbol<'a,unsafe extern "C" fn() -> i8> = unsafe { + &lib.get:: i8>(b"any_maximized\0")? + }; + + Ok(CoreModule { + module: Arc::clone(&lib), + set_wallpaper:Arc::new(set_fn), + any_maximized:Arc::new(any_fn), + }) + } +} #[tauri::command] pub async fn set_wallpaper(title: String) -> bool { @@ -10,8 +35,15 @@ pub async fn set_wallpaper(title: String) -> bool { unsafe { let res = set(title.as_ptr()); if res == 0 { + drop(lib); return false; }; } + drop(lib); return true; -} \ No newline at end of file +} + +#[tauri::command] +pub async fn anyZoomed()->bool{ + let Library +}