Skip to content

Commit 43eb004

Browse files
committed
Change development environment from VSCode to neovim + neovide + clangd.
Yeah, and add some powershell scripts so that I can compile and build this project manually. And fix some header file path problems.
1 parent c3b07e6 commit 43eb004

File tree

8 files changed

+168
-54
lines changed

8 files changed

+168
-54
lines changed

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
BasedOnStyle: Google
3+
IndentWidth: 4

DeclareDPIAware.manifest

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
22
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
3-
<!-- <security>
4-
<requestedPrivileges>
5-
<requestedExecutionLevel
6-
level="highestAvailable"
7-
uiAccess="true" />
8-
</requestedPrivileges>
9-
</security> -->
10-
<!-- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
11-
<security>
12-
<requestedPrivileges>
13-
<requestedExecutionLevel level="requireAdministrator" uiAccess="true" />
14-
</requestedPrivileges>
15-
</security>
16-
</trustInfo> -->
173
<asmv3:application>
184
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
195
<dpiAware>true</dpiAware>

compile.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# generate and compile exe files
2+
3+
$currentDirectory = Get-Location
4+
$cmakeListsPath = Join-Path -Path $currentDirectory -ChildPath "CMakeLists.txt"
5+
6+
if (-not (Test-Path $cmakeListsPath))
7+
{
8+
Write-Host("No CMakeLists.txt in current directory, please check.")
9+
return
10+
}
11+
12+
Write-Host "Start generating and compiling..."
13+
14+
$buildFolderPath = ".\build"
15+
16+
if (-not (Test-Path $buildFolderPath))
17+
{
18+
New-Item -ItemType Directory -Path $buildFolderPath | Out-Null
19+
Write-Host "build folder created."
20+
}
21+
22+
cmake -G "Visual Studio 17 2022" -A x64 -S . -B ./build/
23+
24+
if ($LASTEXITCODE -eq 0)
25+
{
26+
cmake --build ./build/ --config DEBUG
27+
}
28+

launch.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# generate, compile and run exe files
2+
3+
$currentDirectory = Get-Location
4+
$cmakeListsPath = Join-Path -Path $currentDirectory -ChildPath "CMakeLists.txt"
5+
6+
if (-not (Test-Path $cmakeListsPath))
7+
{
8+
Write-Host("No CMakeLists.txt in current directory, please check.")
9+
return
10+
}
11+
12+
Write-Host "Start generating and compiling..."
13+
14+
$buildFolderPath = ".\build"
15+
16+
if (-not (Test-Path $buildFolderPath))
17+
{
18+
New-Item -ItemType Directory -Path $buildFolderPath | Out-Null
19+
Write-Host "build folder created."
20+
}
21+
22+
cmake -G "Visual Studio 17 2022" -A x64 -S . -B ./build/
23+
24+
if ($LASTEXITCODE -eq 0)
25+
{
26+
cmake --build ./build/ --config DEBUG
27+
if ($LASTEXITCODE -eq 0)
28+
{
29+
$content = Get-Content -Path "./CMakeLists.txt"
30+
foreach($line in $content)
31+
{
32+
if ($line.StartsWith("add_executable"))
33+
{
34+
$pattern = "\((.*?)\)"
35+
if ($line -match $pattern)
36+
{
37+
$contentInParentheses = $Matches[1]
38+
$result = -split $contentInParentheses
39+
$exePath = "./build/DEBUG/" + $result[0] + ".exe"
40+
Invoke-Expression $exePath
41+
}
42+
}
43+
}
44+
}
45+
}
46+

main.cpp

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
注意!!!Caution!!!
3-
这个输入法一开始的状态是英文!需要使用 Ctrl + Space 切换一下状态才可以正常输入中文!!!
3+
这个输入法一开始的状态是英文!需要使用 Ctrl + Space
4+
切换一下状态才可以正常输入中文!!!
45
*/
56
#ifndef UNICODE
67
#define UNICODE
@@ -17,17 +18,18 @@
1718

1819
#include "./InitConsole.h"
1920
#include "./flypytblsqlite.h"
20-
#include "./hook/ime_hook.h"
21-
#include "./hook/key_handle_func_lib.h"
22-
#include "./sqlite/sqlite_wrapper.h"
23-
#include "./ui/cand_ui.h"
21+
#include "./src/hook/ime_hook.h"
22+
#include "./src/hook/key_handle_func_lib.h"
23+
#include "./src/sqlite/sqlite_wrapper.h"
24+
#include "./src/ui/cand_ui.h"
25+
#include "./src/utils/caret_helper.h"
2426
#include "./uiaccess.h"
25-
#include "./utils/caret_helper.h"
2627

2728
#pragma comment(lib, "d2d1.lib")
2829
#pragma comment(lib, "dwrite.lib")
2930

30-
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
31+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
32+
int iCmdShow) {
3133
// Windos topmost
3234
PrepareForUIAccess();
3335
// 测试是否有内存泄露
@@ -43,7 +45,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
4345
freopen_s(&pCout, "CONOUT$", "w", stdout);
4446
// SetConsoleTitleW("Debug Console");
4547
SetConsoleTitleW(L"Fany Debug");
46-
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
48+
SetConsoleTextAttribute(
49+
GetStdHandle(STD_OUTPUT_HANDLE),
50+
FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
4751
}
4852
// set std::cout to use my custom streambuf
4953
outbuf ob;
@@ -66,7 +70,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
6670
// 初始化小鹤双拼的码表,纯双拼二码
6771
// std::string dbPath = "../../src/flyciku.db";
6872
std::string dbPath = "./db/flyciku.db";
69-
// sqlPageMap = transTableToMap(dbPath, 8); // 如果把这个放到钩子函数里面会导致程序很慢的
73+
// sqlPageMap = transTableToMap(dbPath, 8); //
74+
// 如果把这个放到钩子函数里面会导致程序很慢的
7075
db = openSqlite(dbPath);
7176
// 初始化 COM
7277
CoInitialize(nullptr); // <-- add this to init COM
@@ -88,14 +93,17 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
8893

8994
// 注册窗口
9095
if (!RegisterClassEx(&winClass)) {
91-
MessageBox(NULL, TEXT("This program requires Windows NT!"), L"error", MB_ICONERROR);
96+
MessageBox(NULL, TEXT("This program requires Windows NT!"), L"error",
97+
MB_ICONERROR);
9298
return 0;
9399
}
94100

95101
// 创建窗口
96-
// 这个 WS_EX_TOOLWINDOW 是为了去掉任务栏区的图标的,这样它就更像一个输入法窗口了
97-
// WS_EX_NOACTIVATE 程序执行之后,窗口不会自动获取焦点
98-
gHwnd = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE,
102+
// 这个 WS_EX_TOOLWINDOW
103+
// 是为了去掉任务栏区的图标的,这样它就更像一个输入法窗口了 WS_EX_NOACTIVATE
104+
// 程序执行之后,窗口不会自动获取焦点
105+
gHwnd = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST |
106+
WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE,
99107
L"Direct2D", // window class name
100108
L"Draw Rectangle", // window caption
101109
WS_POPUP, // window style
@@ -126,25 +134,43 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
126134
while (GetMessage(&msg, NULL, 0, 0)) {
127135
if (msg.message == WM_FANY_HIDEWINDOW) {
128136
// ShowWindow(gHwnd, SW_HIDE);
129-
SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
130-
// SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
137+
SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0,
138+
SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE |
139+
SWP_NOZORDER | SWP_NOACTIVATE);
140+
// SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW |
141+
// SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
131142
} else if (msg.message == WM_FANY_SHOWWINDOW) {
132143
// ShowWindow(gHwnd, SW_SHOW);
133-
// SetWindowPos(gHwnd, NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
134-
// SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
135-
// SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
136-
SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
137-
// SetWindowPos(gHwnd, HWND_DESKTOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
144+
// SetWindowPos(gHwnd, NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE
145+
// | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
146+
// SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW |
147+
// SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
148+
// SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW |
149+
// SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
150+
SetWindowPos(gHwnd, HWND_TOPMOST, 0, 0, 0, 0,
151+
SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
152+
// SetWindowPos(gHwnd, HWND_DESKTOP, 0, 0, 0, 0, SWP_SHOWWINDOW |
153+
// SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
138154
} else if (msg.message == WM_FANY_REDRAW) {
139-
// wText = L"ni'hc\n1.还行\n2.世界\n3.毛笔\n4.量子\n5.笔画\n6.竟然\n7.什么\n8.可是";
155+
// wText =
156+
// L"ni'hc\n1.还行\n2.世界\n3.毛笔\n4.量子\n5.笔画\n6.竟然\n7.什么\n8.可是";
140157
std::pair<int, int> candSize = calcCandSize(17, 2);
141158
// std::pair<int, int> caretPos = fanyGetCaretPos();
142159
std::pair<int, int> caretPos = getGeneralCaretPos();
143-
// SetWindowPos(gHwnd, NULL, caretPos.first, caretPos.second, candSize.first, candSize.second, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
144-
// SetWindowPos(gHwnd, HWND_TOPMOST, caretPos.first, caretPos.second, candSize.first, candSize.second, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
145-
// SetWindowPos(gHwnd, HWND_TOPMOST, caretPos.first, caretPos.second, candSize.first, candSize.second, SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
146-
SetWindowPos(gHwnd, HWND_TOPMOST, caretPos.first, caretPos.second, candSize.first, candSize.second, SWP_SHOWWINDOW | SWP_ASYNCWINDOWPOS);
147-
// SetWindowPos(gHwnd, HWND_DESKTOP, caretPos.first, caretPos.second, candSize.first, candSize.second, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
160+
// SetWindowPos(gHwnd, NULL, caretPos.first, caretPos.second,
161+
// candSize.first, candSize.second, SWP_SHOWWINDOW | SWP_NOZORDER |
162+
// SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS); SetWindowPos(gHwnd,
163+
// HWND_TOPMOST, caretPos.first, caretPos.second, candSize.first,
164+
// candSize.second, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOACTIVATE |
165+
// SWP_ASYNCWINDOWPOS); SetWindowPos(gHwnd, HWND_TOPMOST,
166+
// caretPos.first, caretPos.second, candSize.first, candSize.second,
167+
// SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
168+
SetWindowPos(gHwnd, HWND_TOPMOST, caretPos.first, caretPos.second,
169+
candSize.first, candSize.second,
170+
SWP_SHOWWINDOW | SWP_ASYNCWINDOWPOS);
171+
// SetWindowPos(gHwnd, HWND_DESKTOP, caretPos.first,
172+
// caretPos.second, candSize.first, candSize.second, SWP_SHOWWINDOW
173+
// | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
148174
FanyDrawText(gHwnd, wText);
149175
} else if (msg.message == WM_HOTKEY) {
150176
if (1 == msg.wParam) {

src/hook/ime_hook.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ LRESULT CALLBACK KBDHook(int nCode, WPARAM wParam, LPARAM lParam) {
364364

365365
// 顿号
366366
if (s->vkCode == VK_OEM_5) {
367+
if (fCtrlDown) {
368+
break; // 这里的作用是不干扰其他快捷键,比如 notion 中的 Ctrl + \ 快捷键
369+
}
367370
if (fShiftDown) {
368371
sendStringToCursor(converter.from_bytes("|"));
369372
} else {

src/hook/ime_hook.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <unordered_map>
1010
#include <vector>
1111

12-
#include "../libs/sqlite/sqlite3.h"
12+
#include "../../libs/sqlite/sqlite3.h"
1313

1414
/*
1515
全局变量部分

uiaccess.cpp

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <tchar.h>
44
#include <tlhelp32.h>
55

6-
static DWORD DuplicateWinloginToken(DWORD dwSessionId, DWORD dwDesiredAccess, PHANDLE phToken) {
6+
static DWORD DuplicateWinloginToken(DWORD dwSessionId, DWORD dwDesiredAccess,
7+
PHANDLE phToken) {
78
DWORD dwErr;
89
PRIVILEGE_SET ps;
910

@@ -19,25 +20,34 @@ static DWORD DuplicateWinloginToken(DWORD dwSessionId, DWORD dwDesiredAccess, PH
1920
pe.dwSize = sizeof(pe);
2021
dwErr = ERROR_NOT_FOUND;
2122

22-
for (bCont = Process32First(hSnapshot, &pe); bCont; bCont = Process32Next(hSnapshot, &pe)) {
23+
for (bCont = Process32First(hSnapshot, &pe); bCont;
24+
bCont = Process32Next(hSnapshot, &pe)) {
2325
HANDLE hProcess;
2426

2527
if (0 != _tcsicmp(pe.szExeFile, TEXT("winlogon.exe"))) {
2628
continue;
2729
}
2830

29-
hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pe.th32ProcessID);
31+
hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE,
32+
pe.th32ProcessID);
3033
if (hProcess) {
3134
HANDLE hToken;
3235
DWORD dwRetLen, sid;
3336

34-
if (OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_DUPLICATE, &hToken)) {
37+
if (OpenProcessToken(
38+
hProcess, TOKEN_QUERY | TOKEN_DUPLICATE, &hToken)) {
3539
BOOL fTcb;
3640

3741
if (PrivilegeCheck(hToken, &ps, &fTcb) && fTcb) {
38-
if (GetTokenInformation(hToken, TokenSessionId, &sid, sizeof(sid), &dwRetLen) && sid == dwSessionId) {
42+
if (GetTokenInformation(hToken, TokenSessionId,
43+
&sid, sizeof(sid),
44+
&dwRetLen) &&
45+
sid == dwSessionId) {
3946
bFound = TRUE;
40-
if (DuplicateTokenEx(hToken, dwDesiredAccess, NULL, SecurityImpersonation, TokenImpersonation, phToken)) {
47+
if (DuplicateTokenEx(
48+
hToken, dwDesiredAccess, NULL,
49+
SecurityImpersonation,
50+
TokenImpersonation, phToken)) {
4151
dwErr = ERROR_SUCCESS;
4252
} else {
4353
dwErr = GetLastError();
@@ -67,19 +77,28 @@ static DWORD CreateUIAccessToken(PHANDLE phToken) {
6777
DWORD dwErr;
6878
HANDLE hTokenSelf;
6979

70-
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE, &hTokenSelf)) {
80+
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE,
81+
&hTokenSelf)) {
7182
DWORD dwSessionId, dwRetLen;
7283

73-
if (GetTokenInformation(hTokenSelf, TokenSessionId, &dwSessionId, sizeof(dwSessionId), &dwRetLen)) {
84+
if (GetTokenInformation(hTokenSelf, TokenSessionId, &dwSessionId,
85+
sizeof(dwSessionId), &dwRetLen)) {
7486
HANDLE hTokenSystem;
7587

76-
dwErr = DuplicateWinloginToken(dwSessionId, TOKEN_IMPERSONATE, &hTokenSystem);
88+
dwErr = DuplicateWinloginToken(dwSessionId, TOKEN_IMPERSONATE,
89+
&hTokenSystem);
7790
if (ERROR_SUCCESS == dwErr) {
7891
if (SetThreadToken(NULL, hTokenSystem)) {
79-
if (DuplicateTokenEx(hTokenSelf, TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_DEFAULT, NULL, SecurityAnonymous, TokenPrimary, phToken)) {
92+
if (DuplicateTokenEx(
93+
hTokenSelf,
94+
TOKEN_QUERY | TOKEN_DUPLICATE |
95+
TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_DEFAULT,
96+
NULL, SecurityAnonymous, TokenPrimary, phToken)) {
8097
BOOL bUIAccess = TRUE;
8198

82-
if (!SetTokenInformation(*phToken, TokenUIAccess, &bUIAccess, sizeof(bUIAccess))) {
99+
if (!SetTokenInformation(*phToken, TokenUIAccess,
100+
&bUIAccess,
101+
sizeof(bUIAccess))) {
83102
dwErr = GetLastError();
84103
CloseHandle(*phToken);
85104
}
@@ -111,7 +130,8 @@ static BOOL CheckForUIAccess(DWORD *pdwErr, DWORD *pfUIAccess) {
111130
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
112131
DWORD dwRetLen;
113132

114-
if (GetTokenInformation(hToken, TokenUIAccess, pfUIAccess, sizeof(*pfUIAccess), &dwRetLen)) {
133+
if (GetTokenInformation(hToken, TokenUIAccess, pfUIAccess,
134+
sizeof(*pfUIAccess), &dwRetLen)) {
115135
result = TRUE;
116136
} else {
117137
*pdwErr = GetLastError();
@@ -140,7 +160,9 @@ DWORD PrepareForUIAccess() {
140160
PROCESS_INFORMATION pi;
141161

142162
GetStartupInfo(&si);
143-
if (CreateProcessAsUser(hTokenUIAccess, NULL, GetCommandLine(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
163+
if (CreateProcessAsUser(hTokenUIAccess, NULL, GetCommandLine(),
164+
NULL, NULL, FALSE, 0, NULL, NULL, &si,
165+
&pi)) {
144166
CloseHandle(pi.hProcess), CloseHandle(pi.hThread);
145167
ExitProcess(0);
146168
} else {

0 commit comments

Comments
 (0)