# window-info **Repository Path**: ofix/window-info ## Basic Information - **Project Name**: window-info - **Description**: cross-platform desktop windows' coordination information for electron application - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-27 - **Last Updated**: 2026-01-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # window-info 跨平台窗口信息获取 Node.js 原生插件。 ## 简介 window-info 是一个基于 Node.js N-API 的原生模块,用于获取系统中当前打开窗口的信息。支持 Windows、macOS 和 Linux 三大桌面平台,提供统一的 API 接口来查询窗口标题、类名、位置、尺寸等属性。 ## 功能特性 - **跨平台支持**:同时支持 Windows、macOS 和 Linux 操作系统 - **窗口枚举**:获取所有窗口或仅可见窗口 - **窗口筛选**:支持按标题模式匹配筛选窗口 - **原生性能**:使用 C++ 原生代码实现,性能高效 - **简单易用**:提供简洁的 Promise/Async 风格 API ## 安装 ```bash npm install window-info ``` ## 使用方法 ```javascript const WindowInfo = require('window-info'); // 获取所有窗口 async function listAllWindows() { const windows = await WindowInfo.getAllWindows(); console.log('所有窗口:', windows); } // 获取可见窗口 async function listVisibleWindows() { const windows = await WindowInfo.getVisibleWindows(); console.log('可见窗口:', windows); } // 按标题模式筛选窗口 async function findWindowsByTitle() { const windows = await WindowInfo.getWindowsByTitle('Chrome'); console.log('标题包含 "Chrome" 的窗口:', windows); } // 执行示例 listAllWindows(); listVisibleWindows(); findWindowsByTitle(); ``` ## API 文档 ### WindowInfo.getAllWindows() 获取系统中所有窗口的列表,包括可见和不可见窗口。 **返回值**:Promise\\> ### WindowInfo.getVisibleWindows() 获取系统中所有可见窗口的列表。 **返回值**:Promise\\> ### WindowInfo.getWindowsByTitle(pattern) 根据标题模式筛选窗口。 **参数**: - `pattern` (string):用于匹配窗口标题的正则表达式模式 **返回值**:Promise\\> ### WindowInfo 对象结构 每个窗口信息对象包含以下属性: | 属性 | 类型 | 描述 | |------|------|------| | id | number | 窗口唯一标识符 | | title | string | 窗口标题 | | class | string | 窗口类名(Linux/Windows)或进程名(macOS) | | x | number | 窗口左上角 X 坐标 | | y | number | 窗口左上角 Y 坐标 | | width | number | 窗口宽度 | | height | number | 窗口高度 | | pid | number | 所属进程 ID | ## 平台说明 ### Windows - 使用 Win32 API 实现 - 需要 Windows 7 及以上版本 ### macOS - 使用 Cocoa/CoreGraphics API 实现 - 需要 macOS 10.10 及以上版本 - 仅获取应用程序窗口,不获取系统 UI 窗口 ### Linux - 使用 X11 API 实现 - 支持常规 X11 窗口管理器 - 针对 UKUI 桌面环境进行了特殊优化 - 需要 DISPLAY 环境变量正确配置 ## 构建要求 - Node.js 12.0.0 或更高版本 - Python 2.7/3.x - C++ 编译器: - Windows: Visual Studio 2017 或更高版本 - macOS: Xcode Command Line Tools - Linux: gcc/g++ 和 make ## 本地开发 ```bash # 安装依赖 npm install # 构建原生模块 npm run build # 运行测试 npm test ``` ## 相关项目 - [node-ffi](https://github.com/node-ffi/node-ffi) - Node.js 外部函数接口 - [node-win](https://github.com/winnr/w) - Windows API 的 Node.js 封装 ## 许可证 本项目基于 MIT 许可证开源。