Skip to content

Commit

Permalink
Merge pull request #36 from ruchuby/develop
Browse files Browse the repository at this point in the history
Starter v0.5.3
  • Loading branch information
AkiChase authored May 12, 2023
2 parents 5d29a93 + 170ad1e commit 22576e9
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 6 deletions.
22 changes: 22 additions & 0 deletions docs/api/searchGuiHwnd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: searchText
author: ruchuby
order: 1
date: 2023-04-15
---

## 定义

```ahk
static searchText {
get => SearchGui.gui.Hwnd
}
```

## 类型

动态属性 \{Int\}

## 说明

**获取**搜索界面hwnd。
6 changes: 5 additions & 1 deletion docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ title: 更新日志
icon: clock
---

## [Starter v0.5.3](https://github.com/ruchuby/Starter/releases/tag/v0.5.3) (2023-05-12)
1. 新增: 窗口切换插件 - [相关文档](https://ruchuby.github.io/Starter/plugin/window-switcher)
2. 修复: PluginHelper模块注释内容错误

## [Starter v0.5.2](https://github.com/ruchuby/Starter/releases/tag/v0.5.2) (2023-05-11)

1. 新增: 关键词快捷键 - [相关文档](https://ruchuby.github.io/Starter/guide/setting/#控制)
2. 优化: 稳定搜索框自动隐藏的时间
3. 修复: 文件选择对话框导航在某些窗口不生效的问题
3. 修复: 智能模式下打开文件搜索插件的错误
4. 修复: 智能模式下打开文件搜索插件的错误

## [Starter v0.5.1](https://github.com/ruchuby/Starter/releases/tag/v0.5.1) (2023-04-16)

Expand Down
Binary file added docs/plugin/images/window-switcher-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/plugin/images/window-switcher-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/plugin/images/window-switcher-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions docs/plugin/window-switcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: 窗口切换
author: ruchuby
date: 2023-05-12
---

## 介绍

窗口切换功能,模仿Switcheroo

显示当前窗口列表,输入内容对列表进行检索,支持拼音首字母。

![窗口切换:无输入内容](./images/window-switcher-1.jpg)

![窗口切换:有输入内容](./images/window-switcher-2.jpg)


## 使用方式

插件入口在启动模式中,其他关键词为`["CKQH"]`

启动该插件启动项,进入窗口切换插件。

当未输入任何内容时,在搜索结果中可以看到当前所有窗口的标题列表,即介绍中的第一张图片。

输入任意文本,即可对窗口标题进行检索,**支持拼音首字母**

最后,启动某列表项即可完成切换到指定窗口。

## 进阶技巧

添加对应的[关键词快捷键](https://ruchuby.github.io/Starter/guide/setting/#控制),可以通过快捷键**快速启动插件**

![窗口切换:关键词快捷键](./images/window-switcher-3.jpg)

参考设置如上图,可以通过按下`Alt` + `CapsLK`快捷键来启动该插件。

:::tip
如果需要用来代替`Alt` + `Tab`功能,请将**按键类型**设置为**自定义****按键内容**设置为`!Tab`
:::
4 changes: 2 additions & 2 deletions src/Gui/AboutGui.ah2
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* @Version: 0.0.3
* @Author: ruchuby
* @LastEditors: ruchuby
* @LastEditTime: 2023-05-11
* @LastEditTime: 2023-05-12
* @Description: 关于界面显示版本信息、项目主页、检查更新
*/
class AboutGui {
static version := "0.5.2"
static version := "0.5.3"
; static gui:=unset

static init() {
Expand Down
205 changes: 205 additions & 0 deletions src/Plugin/窗口切换.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/**
* @Name: 窗口切换
* @Version: 0.0.1
* @Author: ruchuby
* @LastEditors: ruchuby
* @LastEditTime: 2023-05-12
* @Description: 窗口切换,支持使用拼音首字母检索窗口标题进行切换,类似Switcheroo
*/

/*
===Starter Plugin Info==>
{
"author": "ruchuby",
"version": "0.0.1",
"introduction": "窗口切换,支持使用拼音首字母检索窗口标题进行切换,类似Switcheroo",
"icon": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAA81JREFUWEftll9oW3UUx7/nd9NMKqZTVtT1bjrSrXeNw4cW0iGjLY048GUKLXN/UF+UbdJ2Ix2ID8sQlC3q2jqQKfqkuGXIRAYTmtmOPZhBYKDE3m2pqe3dyli3ka7t/nT3d+TepNrWpLnZXPegPwiXJN9zvh/OOb/7+xEe8qKH7I//CAAzeQ8PqKS4VHaXGAMbKoanK3/fFag5FC8Zf3yJyiRUlqYKIhWgCgDWUwVYBWB9/3sxH1bYtUffqJ53DFAZGSkHTTULoNpOzqyybYInZ6QeAWAAZIDYYImLYDYg2IBUDHhuGzzuahSkvA7gKX502XpHACuPDgXB/L6VnAhnbQMpL1omxMK44zKNlLnCQAuZToZ61ZHUBiZxDJBvFgTwRobXC8gTTLwl2fzsN04MnGhWHh3qZWmeKghgCcE8eaHlmZedJHaqKQ4A0C80L982N3lp+49PL1qkeK0hB5B98tKs7rwQfPD6vhd/zQXlGED99JdNd2/eWnrzSnoCyBjN+JQCuA4gBcLvYEoC5gAxJZnoPQABKZXVNz5u1OdCzAvgCZ58hwS/AUZNJpCHQZRixqAABi0zk0VSlsjkxAeBy/nKXtYRPQYQp8NNrzoG8ASjG4nwLTPvJcHHpSJSNz4MXHXa25m6xcGeBib6Mh0OWFWbtfJWoGx3NA6mnnS46d1cpr61nzxhQtFYkkZkLrc1RHH95/bjc/VZgN50OPCPYc8L4An2hBQF31Wc7p8070JjkhpIVDGxRgwNQHnG1O75ULZFDQR83R9r25qjAs4AtLoDIYDWALQKsI1cACYAWAOkE+OcFKwTFF0Zu3oukQjdmTarruv0S1BMYfIlzrT+Nv374o6f6hmyb94KVPq7PS7iE9awAGYURKPEQp9i6MkzrYbT3mt13b2AeUqP7QwVBaCt7XwJTF/psbbZB4ZT56zu3gHs0iv1eqy1sUjPWfKiASJ/MBPtoEzvFxag8kgqRCT2MOBbEIDyWu9eEkp95p3GDQAusSk3J19b0bcQAN+X13q7pvtFhEE3XD8kWpZds3fzg2xBWUf0CwBL0uHAK/nm64EBlHWcbAY4woQtY/sDee8R/zrAyLo1Vq8bwDzMEPvHPmo6ON/uotX+zu1M9LYea3v+frZhVV1Xkpg/u7zuuZ7bbveVydHSUXxeO1UoJ2n+rhoQ4gTe1R9rP1AoINf/mr/rLRAOzX0VO8lln1I+f3e1KRABs89JUA7NJUBu1mM7+4qN/+uYrHph32NkurMXkOLSKI+444m+HePFRWXUBS+l95K0mJj/Af4E/+8XBQoX0rkAAAAASUVORK5CYII="
}
<==Starter Plugin Info===
*/


#Include ..\Utils\PluginHelper.ah2
PluginHelper.addEntryFunc((*) => Plugin_窗口切换.main()) ; 添加入口函数等待执行

#DllLoad "dwmapi" ; 预先加载dwmapi.dll

class Plugin_窗口切换 {

static main() {
SplitPath(A_LineFile, &name) ; 获取插件id即文件名
this.name := name
this.hwnd := PluginHelper.searchGuiHwnd

this.addToStartupMode()
}

; 获取所有窗口列表(结果和Alt+Tab一致)
static getAllAltWinList() ; v0.21 by SKAN for ah2 on D51K/D51O @ autohotkey.com/r?t=99157
{
Static S_OK := 0 ; 非0时表示DwmGetWindowAttribute函数错误

Local List := []
, Style := 0
, ExStyle := 0
, hwnd := 0

For , hwnd in WinGetList()
If IsVisible(hwnd)
&& StyledRight(hwnd)
&& IsAltTabWindow(hwnd)
List.Push(hwnd)

Return List

IsVisible(hwnd, Cloaked := 0)
{
If S_OK = 0
S_OK := DllCall("dwmapi\DwmGetWindowAttribute", "ptr", hwnd
, "int", 14 ; DWMWA_CLOAKED
, "uintp", &Cloaked
, "int", 4 ; sizeof uint
)

Style := WinGetStyle(hwnd)
Return (Style & 0x10000000) && !Cloaked ; WS_VISIBLE
}


StyledRight(hwnd)
{
ExStyle := WinGetExStyle(hwnd)

Return (ExStyle & 0x8000000) ? False ; WS_EX_NOACTIVATE
: (ExStyle & 0x40000) ? True ; WS_EX_APPWINDOW
: (ExStyle & 0x80) ? False ; WS_EX_TOOLWINDOW
: True
}


IsAltTabWindow(Hwnd)
{

ExStyle := WinGetExStyle(hwnd)
If (ExStyle & 0x40000) ; WS_EX_APPWINDOW
Return True

While hwnd := DllCall("GetParent", "ptr", hwnd, "ptr")
{
If IsVisible(Hwnd)
Return False

ExStyle := WinGetExStyle(hwnd)

If (ExStyle & 0x80) ; WS_EX_TOOLWINDOW
&& !(ExStyle & 0x40000) ; WS_EX_APPWINDOW
Return False
}

Return !Hwnd
}
}

; 获取匹配搜索的窗口信息列表
static getWinList(searchText) {
o := A_DetectHiddenWindows
DetectHiddenWindows(false)

out := []
idList := this.getAllAltWinList()
for id in idList {
; 窗口不存在则跳过
if (!WinExist("ahk_id " id))
continue

title := WinGetTitle()
if (
id == this.hwnd || ; 是主程序窗口则跳过
; 带有搜索内容 且 标题或转拼音首字母后 都不包含搜索文本则跳过
searchText &&
!(
InStr(title, searchText) ||
Instr(PluginHelper.Utils.chineseFirstChar(title), searchText) ; 标题中文
)
)
continue

; 获取hIcon
if !(hIcon := SendMessage(0x7F, 0, 0))
if !(hIcon := SendMessage(0x7F, 1, 0))
if (!(hIcon := SendMessage(0x7F, 2, 0)))
if (!(hIcon := DllCall("GetClassLongPtr", "Ptr", id, "Int", -14, "Ptr")))
if (!(hIcon := DllCall("GetClassLongPtr", "Ptr", id, "Int", -34, "Ptr")))
hIcon := DllCall("LoadIcon", "uint", 0, "uint", 32512) ; 使用默认图标

; 添加到输出列表
out.push({ hwnd: id, title: title, hIcon: hIcon })
}

DetectHiddenWindows(o)

if (out.Length >= 2) {
; 交换1,2元素位置
tmp := out[1]
out[1] := out[2]
out[2] := tmp
}
return out
}

static addToStartupMode() {
searchHandler(that, searchText) {
that.pluginSearchResult := this.getWinList(searchText)

; 定义了loadImgsHandler,重载当前图像列表
that.reloadLVIL(true)

; 重新加载列表
that.listView.Opt("-Redraw") ;禁用重绘

; that.listView.Delete() ; reloadLVIL中已经删除了
for item in that.pluginSearchResult
that.listView.Add("icon" that.imgPathToImgListIndex[item.hwnd], " " item.title)

that.resizeGui() ;根据搜索结果数量调整gui尺寸 并启用重绘
}

runHandler(that, rowNum) {
; 激活对应窗口然后隐藏搜索框
hwnd := that.pluginSearchResult[rowNum].hwnd
try WinActivate("ahk_id " hwnd)
catch {
; 激活失败则重载搜索结果
searchHandler(that, PluginHelper.searchText)
return
}
PluginHelper.hideSearchGui()
}

loadImgsHandler(that) {
static defaultHIcon := DllCall("LoadIcon", "uint", 0, "uint", 32512) ; 默认图标

that.imgPathToImgListIndex["default"] := IL_Add(that.imgListID, "hIcon:*" defaultHIcon)
for item in that.pluginSearchResult {
; hwnd作为路径
index := IL_Add(that.imgListID, "hIcon:*" item.hIcon)
; 加载失败则使用默认图标
that.imgPathToImgListIndex[item.hwnd] := index ? index : that.imgPathToImgListIndex["default"]
}
}

PluginHelper.addPluginToStartupMode(
this.name,
"窗口切换",
["CKQH"],
(*) => PluginHelper.showPluginMode(
[],
searchHandler,
runHandler, {
loadImgsHandler: loadImgsHandler,
thumb: PluginHelper.getPluginHIcon(this.name)
}
)
)
}
}
3 changes: 2 additions & 1 deletion src/Starter.ah2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Version: 0.5.2
* @Author: ruchuby
* @LastEditors: ruchuby
* @LastEditTime: 2023-05-11
* @LastEditTime: 2023-05-12
* @Description: 介绍Starter 是一款AHK编写的快速启动工具,旨在方便快捷地启动文件、文件夹,提高电脑的使用效率。
*/
#NoTrayIcon ; 先隐藏图标
Expand All @@ -20,6 +20,7 @@ SetWinDelay(0)
; 调试模式下,退出时不保存用户数据,不会动态载入插件
; 手动#inclide 需要调试的插件
; DEBUG := true
; #Include .\Plugin\窗口切换.ahk
; #Include .\Plugin\文件搜索.ahk
; #Include .\Plugin\文件选择对话框导航.ahk
; #Include .\Plugin\网页搜索.ahk
Expand Down
11 changes: 9 additions & 2 deletions src/Utils/PluginHelper.ah2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Version: 0.0.3
* @Author: ruchuby
* @LastEditors: ruchuby
* @LastEditTime: 2023-04-16
* @LastEditTime: 2023-05-12
* @Description: 插件API封装
*/

Expand All @@ -18,6 +18,13 @@ class PluginHelper {
IntelligentMode.pluginLoadImgs()
}

/**
* @description 返回搜索界面hwnd
* @link [searchGuiHwnd | Starter文档](https://ruchuby.github.io/Starter/api/searchGuiHwnd)
* @type {Int}
*/
static searchGuiHwnd => SearchGui.gui.Hwnd

/**
* @description 插件菜单对象,菜单位于:托盘菜单 > 插件功能
* @link [pluginMenu | Starter文档](https://ruchuby.github.io/Starter/api/pluginMenu)
Expand Down Expand Up @@ -259,7 +266,7 @@ class PluginHelper {
/**
* @description: 启动插件模式
* @link [showPluginMode | Starter文档](https://ruchuby.github.io/Starter/api/showPluginMode)
* @param {Object} pluginSearchData 用于插件模式搜索的数据
* @param {Array} pluginSearchData 用于插件模式搜索的数据
* @param {(that, searchText) => void} searchHandler 插件模式搜索处理函数
* @param {(that, rowNum) => void} runHandler 插件模式回车、双击任意项时的处理函数
* @param {Object} [options] 可选参数对象
Expand Down

0 comments on commit 22576e9

Please sign in to comment.