Skip to content

Commit

Permalink
feat: support windows-arm (#84)
Browse files Browse the repository at this point in the history
* feat: support windows arm

* add windows-arm to ci

* add new target: i686-pc-windows-msvc

* set version to 1.4.0-rc1

* update inspect-windows

* remove target(aarch64-pc-windows-msvc) from ci

* update inspect-windows

* update release ci
  • Loading branch information
sigoden authored Nov 5, 2023
1 parent 915644c commit 2f83766
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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-$version-$platform
executable=target/$target/release/$bin
if [[ "$RUNNER_OS" == "Windows" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "window-switcher"
version = "1.3.3"
version = "1.4.0-rc1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
6 changes: 3 additions & 3 deletions src/utils/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn get_module_icon(hwnd: HWND) -> Option<HICON> {
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) }
}
Expand All @@ -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) }
}
Expand All @@ -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) }
}
Expand Down
76 changes: 61 additions & 15 deletions tools/inspect-windows/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
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<()> {
let output = collect_windows_info()?
.iter()
.map(|v| v.stringify())
.collect::<Vec<String>>()
.join("\n");
println!("{output}");
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,
}

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<Vec<WindowInfo>> {
let mut hwnds: Vec<HWND> = 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);
Expand All @@ -21,21 +63,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 {
Expand All @@ -51,3 +92,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();
}

0 comments on commit 2f83766

Please sign in to comment.