From ea624ac195092213e6d1815422534208b5ff2929 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 09:44:54 +0800 Subject: [PATCH 1/8] feat: support windows arm --- src/utils/window.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/window.rs b/src/utils/window.rs index 128e377..39cf967 100644 --- a/src/utils/window.rs +++ b/src/utils/window.rs @@ -171,7 +171,7 @@ pub fn get_module_icon(hwnd: HWND) -> Option { pub fn get_window_user_data(hwnd: HWND) -> i32 { unsafe { windows::Win32::UI::WindowsAndMessaging::GetWindowLongW(hwnd, GWL_USERDATA) } } -#[cfg(target_arch = "x86_64")] +#[cfg(not(target_arch = "x86"))] pub fn get_window_user_data(hwnd: HWND) -> isize { unsafe { windows::Win32::UI::WindowsAndMessaging::GetWindowLongPtrW(hwnd, GWL_USERDATA) } } @@ -181,7 +181,7 @@ pub fn set_window_user_data(hwnd: HWND, ptr: i32) -> i32 { unsafe { windows::Win32::UI::WindowsAndMessaging::SetWindowLongW(hwnd, GWL_USERDATA, ptr) } } -#[cfg(target_arch = "x86_64")] +#[cfg(not(target_arch = "x86"))] pub fn set_window_user_data(hwnd: HWND, ptr: isize) -> isize { unsafe { windows::Win32::UI::WindowsAndMessaging::SetWindowLongPtrW(hwnd, GWL_USERDATA, ptr) } } @@ -190,7 +190,7 @@ pub fn set_window_user_data(hwnd: HWND, ptr: isize) -> isize { pub fn get_class_icon(hwnd: HWND) -> u32 { unsafe { windows::Win32::UI::WindowsAndMessaging::GetClassLongW(hwnd, GCL_HICON) } } -#[cfg(target_arch = "x86_64")] +#[cfg(not(target_arch = "x86"))] pub fn get_class_icon(hwnd: HWND) -> usize { unsafe { windows::Win32::UI::WindowsAndMessaging::GetClassLongPtrW(hwnd, GCL_HICON) } } From ed14a35a70005da2c6b08bf74c1c38abf58b979e Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:11:59 +0800 Subject: [PATCH 2/8] add windows-arm to ci --- .github/workflows/release.yaml | 9 ++++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0e1955f..33ba668 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,8 +19,14 @@ jobs: include: - target: x86_64-pc-windows-msvc os: windows-latest + platform: windows-64 - target: i686-pc-windows-msvc os: windows-latest + platform: windows-32 + use-cross: true + - target: aarch64-pc-windows-msvc + os: windows-latest + platform: windows-arm use-cross: true runs-on: ${{matrix.os}} @@ -78,13 +84,14 @@ jobs: id: package env: target: ${{ matrix.target }} + platform: ${{ matrix.platform }} version: ${{ steps.check-tag.outputs.version }} run: | set -euxo pipefail bin=${GITHUB_REPOSITORY##*/} dist_dir=`pwd`/dist - name=$bin-$version-$target + name=$bin-$platform executable=target/$target/release/$bin if [[ "$RUNNER_OS" == "Windows" ]]; then diff --git a/Cargo.lock b/Cargo.lock index e912e00..524a21b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,7 +378,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "window-switcher" -version = "1.3.3" +version = "1.4.0" dependencies = [ "anyhow", "embed-resource", diff --git a/Cargo.toml b/Cargo.toml index 42a22e8..4387cfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "window-switcher" -version = "1.3.3" +version = "1.4.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From f3c9739154fe3b26021f3e8c900f31a34888243f Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:12:51 +0800 Subject: [PATCH 3/8] add new target: i686-pc-windows-msvc --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f3ee2fb..6d342d0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,6 +26,8 @@ jobs: os: windows-latest - target: i686-pc-windows-msvc os: windows-latest + - target: aarch64-pc-windows-msvc + os: windows-latest runs-on: ${{matrix.os}} From e316ee7e00188fc00452cce3c89e8afe57ec7b52 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:13:51 +0800 Subject: [PATCH 4/8] set version to 1.4.0-rc1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 524a21b..fecec23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,7 +378,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "window-switcher" -version = "1.4.0" +version = "1.4.0-rc1" dependencies = [ "anyhow", "embed-resource", diff --git a/Cargo.toml b/Cargo.toml index 4387cfa..71a8356 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "window-switcher" -version = "1.4.0" +version = "1.4.0-rc1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 3a9190bb10e81d0cf8e02ff45df26d26c5f16832 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:33:17 +0800 Subject: [PATCH 5/8] update inspect-windows --- tools/inspect-windows/src/main.rs | 80 +++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/tools/inspect-windows/src/main.rs b/tools/inspect-windows/src/main.rs index 9ddc111..d369c7c 100644 --- a/tools/inspect-windows/src/main.rs +++ b/tools/inspect-windows/src/main.rs @@ -1,13 +1,59 @@ -use anyhow::{anyhow, Result}; +use anyhow::{Context, Result}; use window_switcher::utils::*; use windows::Win32::Foundation::{BOOL, HWND, LPARAM}; use windows::Win32::UI::WindowsAndMessaging::{EnumWindows, GetWindow, GW_OWNER}; fn main() -> Result<()> { + for window_info in collect_windows_info()? { + let WindowInfo { + hwnd, + title, + owner_hwnd, + owner_title, + size, + is_visible, + is_cloaked, + is_iconic, + is_topmost, + } = window_info; + + let size = format!("{}x{}", size.0, size.1); + + println!( + "visible:{}cloacked{}iconic{}topmost:{} {:>10} {:>10}:{} {}:{}", + pretty_bool(is_visible), + pretty_bool(is_cloaked), + pretty_bool(is_iconic), + pretty_bool(is_topmost), + size, + hwnd.0, + title, + owner_hwnd.0, + owner_title + ); + } + Ok(()) +} + +#[derive(Debug)] +struct WindowInfo { + hwnd: HWND, + title: String, + owner_hwnd: HWND, + owner_title: String, + size: (usize, usize), + is_visible: bool, + is_cloaked: bool, + is_iconic: bool, + is_topmost: bool, +} + +fn collect_windows_info() -> anyhow::Result> { let mut hwnds: Vec = Default::default(); unsafe { EnumWindows(Some(enum_window), LPARAM(&mut hwnds as *mut _ as isize)) } - .map_err(|e| anyhow!("Fail to get windows {}", e))?; + .with_context(|| "Fail to enum windows".to_string())?; + let mut output = vec![]; for hwnd in hwnds { let title = get_window_title(hwnd); let is_cloaked = is_cloaked_window(hwnd); @@ -21,21 +67,20 @@ fn main() -> Result<()> { } else { "".into() }; - let size = format!("{width}x{height}"); - println!( - "visible:{}cloacked{}iconic{}topmost:{} {:>10} {:>10}:{} {}:{}", - pretty_bool(is_visible), - pretty_bool(is_cloaked), - pretty_bool(is_iconic), - pretty_bool(is_topmost), - size, - hwnd.0, + let window_info = WindowInfo { + hwnd, title, - owner_hwnd.0, - owner_title - ); + owner_hwnd, + owner_title, + size: (width as usize, height as usize), + is_visible, + is_cloaked, + is_iconic, + is_topmost, + }; + output.push(window_info); } - Ok(()) + Ok(output) } fn pretty_bool(value: bool) -> String { @@ -51,3 +96,8 @@ extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL { windows.push(hwnd); BOOL(1) } + +#[test] +fn test_collect_windows_info() { + collect_windows_info().unwrap(); +} From e5d781760dc43add2661ce12968ef76d0b3947e0 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:39:18 +0800 Subject: [PATCH 6/8] remove target(aarch64-pc-windows-msvc) from ci --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6d342d0..f3ee2fb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,8 +26,6 @@ jobs: os: windows-latest - target: i686-pc-windows-msvc os: windows-latest - - target: aarch64-pc-windows-msvc - os: windows-latest runs-on: ${{matrix.os}} From c49784e2679719c51bf5f3c52b6dfc7b5a27b000 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:45:03 +0800 Subject: [PATCH 7/8] update inspect-windows --- tools/inspect-windows/src/main.rs | 52 ++++++++++++++----------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/tools/inspect-windows/src/main.rs b/tools/inspect-windows/src/main.rs index d369c7c..51fd0ec 100644 --- a/tools/inspect-windows/src/main.rs +++ b/tools/inspect-windows/src/main.rs @@ -5,34 +5,12 @@ use windows::Win32::Foundation::{BOOL, HWND, LPARAM}; use windows::Win32::UI::WindowsAndMessaging::{EnumWindows, GetWindow, GW_OWNER}; fn main() -> Result<()> { - for window_info in collect_windows_info()? { - let WindowInfo { - hwnd, - title, - owner_hwnd, - owner_title, - size, - is_visible, - is_cloaked, - is_iconic, - is_topmost, - } = window_info; - - let size = format!("{}x{}", size.0, size.1); - - println!( - "visible:{}cloacked{}iconic{}topmost:{} {:>10} {:>10}:{} {}:{}", - pretty_bool(is_visible), - pretty_bool(is_cloaked), - pretty_bool(is_iconic), - pretty_bool(is_topmost), - size, - hwnd.0, - title, - owner_hwnd.0, - owner_title - ); - } + let output = collect_windows_info()? + .iter() + .map(|v| v.stringify()) + .collect::>() + .join("\n"); + println!("{output}"); Ok(()) } @@ -49,6 +27,24 @@ struct WindowInfo { is_topmost: bool, } +impl WindowInfo { + pub fn stringify(&self) -> String { + let size = format!("{}x{}", self.size.0, self.size.1); + format!( + "visible:{}cloacked{}iconic{}topmost:{} {:>10} {:>10}:{} {}:{}", + pretty_bool(self.is_visible), + pretty_bool(self.is_cloaked), + pretty_bool(self.is_iconic), + pretty_bool(self.is_topmost), + size, + self.hwnd.0, + self.title, + self.owner_hwnd.0, + self.owner_title + ) + } +} + fn collect_windows_info() -> anyhow::Result> { let mut hwnds: Vec = Default::default(); unsafe { EnumWindows(Some(enum_window), LPARAM(&mut hwnds as *mut _ as isize)) } From 6dc22c7cf4276aa5f1a542f9107ebabe18432727 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Nov 2023 10:54:49 +0800 Subject: [PATCH 8/8] update release ci --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 33ba668..f288e7c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -91,7 +91,7 @@ jobs: bin=${GITHUB_REPOSITORY##*/} dist_dir=`pwd`/dist - name=$bin-$platform + name=$bin-$version-$platform executable=target/$target/release/$bin if [[ "$RUNNER_OS" == "Windows" ]]; then