Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2efb1f6978 | ||
|
|
8b149e9ff9 | ||
|
|
2d376ef694 | ||
|
|
1367fd6636 | ||
|
|
5a70d35c27 | ||
|
|
0da8464fce | ||
|
|
d261b079c6 | ||
|
|
2b312f33e6 | ||
|
|
b3f0f4ab0f | ||
|
|
1f97e9c50e | ||
|
|
f740e7195d | ||
|
|
20930dd05c | ||
|
|
f76796c7ea | ||
|
|
62bb55bccc | ||
|
|
86346df08e | ||
|
|
211a6bdb33 | ||
|
|
240cc535ba | ||
|
|
8c7129917c | ||
|
|
92b72c2e7b | ||
|
|
59d01375ff | ||
|
|
2ffee2f880 | ||
|
|
e5987dee22 | ||
|
|
77aa5b7894 |
No files matched your search
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(KSwitcher VERSION 0.8.10 LANGUAGES C CXX RC)
|
||||
project(KSwitcher VERSION 0.8.15 LANGUAGES C CXX RC)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
|
||||
endif()
|
||||
@@ -70,7 +70,10 @@ target_link_libraries(KSwitcherFiles PRIVATE kscore)
|
||||
target_include_directories(kscore PUBLIC src PRIVATE vendor "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
target_compile_definitions(kscore PUBLIC UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX _WIN32_WINNT=0x0A00)
|
||||
target_link_libraries(kscore PUBLIC ws2_32 bcrypt iphlpapi winhttp user32 shell32 shlwapi advapi32 crypt32 imm32 comctl32 gdi32 ole32 oleaut32 taskschd comdlg32 uuid windowscodecs runtimeobject uiautomationcore dwmapi)
|
||||
file(GLOB KSWITCHER_NAVIGATION_ICONS CONFIGURE_DEPENDS "resources/icons/navigation/*.ico")
|
||||
set_property(SOURCE resources/app.rc APPEND PROPERTY OBJECT_DEPENDS
|
||||
${KSWITCHER_NAVIGATION_ICONS}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/resources/navigation_icons.inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/resources/update.ps1"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/resources/kswitcher.ico"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/resources/kswitcher-paused.ico"
|
||||
@@ -390,6 +393,8 @@ set_tests_properties(clipboard-history-layout PROPERTIES RUN_SERIAL TRUE TIMEOUT
|
||||
add_test(NAME offline-help-window COMMAND KSwitcherInputTests --help-layout)
|
||||
set_tests_properties(offline-help-window PROPERTIES RUN_SERIAL TRUE TIMEOUT 20)
|
||||
add_test(NAME tray-input-pause COMMAND KSwitcherInputTests --input-pause)
|
||||
add_test(NAME navigation-icons COMMAND KSwitcherInputTests --navigation-icons)
|
||||
set_tests_properties(navigation-icons PROPERTIES TIMEOUT 20)
|
||||
add_test(NAME screenshot-ui-regressions COMMAND KSwitcherScreenshotUITests)
|
||||
add_test(NAME screenshot-editor-layout COMMAND KSwitcherScreenshotUITests --layout-only)
|
||||
set_tests_properties(screenshot-editor-layout PROPERTIES RUN_SERIAL TRUE TIMEOUT 20)
|
||||
|
||||
@@ -139,6 +139,17 @@ a green dot when all online paired PCs are connected, and a red dot if the LAN
|
||||
worker stops. Hover over the icon to see the connection status and the connected
|
||||
count when only some paired PCs are connected.
|
||||
|
||||
If a held key or button blocks a handoff, the tray and **Settings → Computers**
|
||||
identify the PC and name the input when available. Starting with v0.8.13, the
|
||||
tray icon shows a steady amber exclamation mark until the input is released or a
|
||||
handoff succeeds.
|
||||
If Windows still sees an input as held, choose **Reset held keys and mouse buttons**
|
||||
in the tray menu. One click resets this PC and sends the request to every
|
||||
paired PC with an active input-sharing connection. Computers with older builds
|
||||
ignore the remote request. An offline PC does not receive it when it reconnects.
|
||||
Both computers need v0.8.12 or later for the source PC to display which input
|
||||
is held on the destination.
|
||||
|
||||
The source cursor is parked and hidden beneath a tiny no-activation window. A
|
||||
small banner identifies remote control; no full-screen layered bitmap is retained.
|
||||
The destination uses its own keyboard layout and runs its own hotkeys/snippets.
|
||||
|
||||
@@ -46,20 +46,24 @@ Saving Settings now merges independent resident/editor changes. If the same fiel
|
||||
changed on both sides, choose whether to retain your draft without closing the
|
||||
window. Declining preserves all draft edits. No export/import workaround is needed.
|
||||
|
||||
## Custom shortcuts — v0.8.9
|
||||
## Custom shortcuts
|
||||
|
||||
In **Settings → Shortcuts → Custom shortcuts**, choose **Add shortcut…** and
|
||||
record a global key combination. **Launch app** can start the program each time
|
||||
or activate its last-used window and start it if closed. **Send text to app**
|
||||
inserts text into an editable Windows **Edit** or **RichEdit** field selected
|
||||
with the KSwitcher crosshair. Use **Apply** or **Save** to activate the rule.
|
||||
with the KSwitcher crosshair. **Open URL** opens an HTTP or HTTPS address in the
|
||||
default browser, Chrome, or a browser executable you choose. For Chrome, you can
|
||||
pick a profile from its standard data folder. Use **Apply** or **Save** to activate the rule.
|
||||
Custom shortcuts are stored on this PC.
|
||||
|
||||
**Українською.** У **Settings → Shortcuts → Custom shortcuts** натисніть
|
||||
**Add shortcut…** і запишіть глобальну комбінацію клавіш. **Launch app** запускає
|
||||
програму щоразу або активує її останнє використане вікно й запускає програму,
|
||||
якщо вона закрита. **Send text to app** вставляє текст у поле Windows **Edit**
|
||||
або **RichEdit**, вибране прицілом KSwitcher. Застосуйте зміни кнопкою **Apply**
|
||||
або **RichEdit**, вибране прицілом KSwitcher. **Open URL** відкриває адресу HTTP
|
||||
або HTTPS у типовому браузері, Chrome чи іншому вказаному браузері. Для Chrome
|
||||
можна вибрати профіль зі стандартної папки даних. Застосуйте зміни кнопкою **Apply**
|
||||
або **Save**. Власні шорткати зберігаються на цьому ПК.
|
||||
|
||||
## Mouse buttons for applications
|
||||
|
||||
@@ -1,5 +1,40 @@
|
||||
# Latest Windows release
|
||||
|
||||
## v0.8.15 — 2026-12-04
|
||||
|
||||
**Settings and tray menu.** Every section in the Settings sidebar and every command in the main tray menu now has an outline icon. Shared commands such as Snippets and keyboard shortcuts use the same symbol in both places.
|
||||
|
||||
**LAN input recovery.** **Reset held keys and mouse buttons** now resets this PC and asks each connected, paired PC to clear stuck input. Update both PCs to use remote reset.
|
||||
|
||||
**Українською.** Усі розділи бічної панелі налаштувань і всі команди головного меню в треї отримали контурні іконки. Спільні команди, як-от Snippets і шорткати, мають однаковий символ в обох меню.
|
||||
|
||||
**Відновлення вводу через LAN.** Команда **«Скинути затиснуті клавіші й кнопки миші»** скидає ввід на цьому ПК і надсилає запит кожному підключеному спареному ПК. Для віддаленого скидання оновіть обидва ПК.
|
||||
|
||||
|
||||
## v0.8.14 — 2026-12-03
|
||||
|
||||
**Clipboard history.** When the open list is at the top, a newly copied or received screenshot appears in the first row. If you have scrolled down to browse older entries, the list keeps your place and preserves your selection.
|
||||
|
||||
**Українською.** Коли відкритий список історії прокручено до початку, новий скріншот після копіювання або отримання з іншого ПК видно в першому рядку. Під час перегляду старіших записів список зберігає позицію прокручування та вибраний запис.
|
||||
|
||||
## v0.8.13 — 2026-12-01
|
||||
|
||||
**Tray warning for LAN cursor handoff.** A steady amber badge with an exclamation mark appears when a held key or mouse button blocks a cursor handoff. Hover over the tray icon to see the affected PC and, when known, the held key or button. The normal connection indicator returns when the input is released or a handoff succeeds.
|
||||
|
||||
**Українською.** Якщо затиснута клавіша чи кнопка миші блокує перехід курсора між ПК, у треї з’являється сталий бурштиновий індикатор зі знаком оклику. Наведіть курсор на значок, щоб побачити, на якому ПК виникло блокування та що саме затиснуто, якщо це вдалося визначити. Після відпускання вводу або успішного переходу повертається звичайний індикатор з’єднання.
|
||||
|
||||
## v0.8.12 — 2026-12-01
|
||||
|
||||
**LAN cursor handoff.** The tray and **Settings → Computers** identify the computer and, when known, the key or mouse button holding up the handoff. If Windows still sees an input as held after you release it, choose **Reset held keys and mouse buttons** from the tray menu on that PC. Update both computers to see which input on the other PC is blocking the handoff.
|
||||
|
||||
**Українською.** Трей і **Налаштування → Комп’ютери** показують, на якому ПК заблоковано перехід курсора та яка клавіша або кнопка миші його блокує, якщо її вдалося визначити. Якщо Windows продовжує вважати ввід затиснутим після відпускання, виберіть **«Скинути затиснуті клавіші й кнопки миші»** у треї на цьому ПК. Оновіть обидва комп’ютери, щоб бачити, який ввід на іншому ПК блокує перехід.
|
||||
|
||||
## v0.8.11 — 2026-11-30
|
||||
|
||||
**Open URL** is a new action in **Settings → Shortcuts → Custom shortcuts**. Open an HTTP or HTTPS address in the default browser, Google Chrome, or another browser by picking its executable. Choose a Chrome profile from its standard data folder if needed. The shortcut editor uses a white content area and the same tinted footer style as Settings.
|
||||
|
||||
**Українською.** У **Settings → Shortcuts → Custom shortcuts** з’явилася дія **Open URL**. Відкривайте адреси HTTP або HTTPS у типовому браузері, Google Chrome або іншому браузері, вказавши його `.exe`. Для Chrome за потреби виберіть профіль зі стандартної папки даних. Редактор шорткатів має білу область вмісту й тонований футер у стилі Settings.
|
||||
|
||||
## v0.8.10 — 2026-11-30
|
||||
|
||||
After **Apply** saves your changes, Settings disables **Apply** and **Save** and offers **Close**, including when **Start with Windows** is enabled. A new edit enables the saving controls again.
|
||||
|
||||
@@ -1 +1 @@
|
||||
e5cb3913c815bbb91f1d455b78589a27dc9ca9fb1cab58d40ef003aad7182779 KSwitcher-win-x64.zip
|
||||
bdc1ddd2cfca17ff040dc52e74f76a3ae3d89e57b4138f75c79339d62b51dc67 KSwitcher-win-x64.zip
|
||||
@@ -1,181 +1,181 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"version": "0.8.10",
|
||||
"files": [
|
||||
{
|
||||
"sha256": "51c2b60bd27676ef92c674033e0a7295ab666c95ec19f0514dc6e6af22787c43",
|
||||
"size": 3283456,
|
||||
"path": "KSwitcher.exe"
|
||||
"path": "KSwitcher.exe",
|
||||
"sha256": "589783aa5bbb7727ebc1ad6dc0987bec6a6d11daaa40e7bcb193be06360a3db2",
|
||||
"size": 3534336
|
||||
},
|
||||
{
|
||||
"sha256": "f3f9f375bde4afc5e0099fc6db5187e5d34e7a1bb4f98e27255b29a0aad36240",
|
||||
"size": 2870784,
|
||||
"path": "KSwitcher.Config.exe"
|
||||
"path": "KSwitcher.Config.exe",
|
||||
"sha256": "4673bb360f53264524e3015fa923c9ecab31073d64f0103916ce27ef95e1e471",
|
||||
"size": 3118592
|
||||
},
|
||||
{
|
||||
"sha256": "bf3c38225db36eb5f73ffb41da7b45094d5c41d08ca74c82dd7612ec563e779d",
|
||||
"size": 3200512,
|
||||
"path": "KSwitcher.Screenshot.exe"
|
||||
"path": "KSwitcher.Screenshot.exe",
|
||||
"sha256": "67ea80117d5db8432b1fbcb30606fd8fc8f91e43cd6a3fe2447c0209fb5b3220",
|
||||
"size": 3427328
|
||||
},
|
||||
{
|
||||
"sha256": "3303797ea63154f9ec3ef302e792884abdaba87f174811cfcf91e1595bc1bfa6",
|
||||
"size": 6019072,
|
||||
"path": "KSwitcher.Files.exe"
|
||||
"path": "KSwitcher.Files.exe",
|
||||
"sha256": "ab882ea94b5ce5a56711ac83f1029cdf13c9c1d88412cf6d3b3b2f6e48708df6",
|
||||
"size": 6040064
|
||||
},
|
||||
{
|
||||
"path": "WebView2Loader.dll",
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6",
|
||||
"size": 194912,
|
||||
"path": "WebView2Loader.dll"
|
||||
"size": 194912
|
||||
},
|
||||
{
|
||||
"path": "terminal/addon-fit-LICENSE.txt",
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f",
|
||||
"size": 1103,
|
||||
"path": "terminal/addon-fit-LICENSE.txt"
|
||||
"size": 1103
|
||||
},
|
||||
{
|
||||
"path": "terminal/addon-fit.js",
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527",
|
||||
"size": 1521,
|
||||
"path": "terminal/addon-fit.js"
|
||||
"size": 1521
|
||||
},
|
||||
{
|
||||
"path": "terminal/index.html",
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef",
|
||||
"size": 527,
|
||||
"path": "terminal/index.html"
|
||||
"size": 527
|
||||
},
|
||||
{
|
||||
"path": "terminal/markdown-it-LICENSE.txt",
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473",
|
||||
"size": 1073,
|
||||
"path": "terminal/markdown-it-LICENSE.txt"
|
||||
"size": 1073
|
||||
},
|
||||
{
|
||||
"path": "terminal/markdown-it.js",
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e",
|
||||
"size": 100786,
|
||||
"path": "terminal/markdown-it.js"
|
||||
"size": 100786
|
||||
},
|
||||
{
|
||||
"path": "terminal/markdown.html",
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2",
|
||||
"size": 3800,
|
||||
"path": "terminal/markdown.html"
|
||||
"size": 3800
|
||||
},
|
||||
{
|
||||
"path": "terminal/markdown.js",
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96",
|
||||
"size": 18721,
|
||||
"path": "terminal/markdown.js"
|
||||
"size": 18721
|
||||
},
|
||||
{
|
||||
"path": "terminal/mermaid-LICENSE.txt",
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80",
|
||||
"size": 1089,
|
||||
"path": "terminal/mermaid-LICENSE.txt"
|
||||
"size": 1089
|
||||
},
|
||||
{
|
||||
"path": "terminal/mermaid.js",
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3",
|
||||
"size": 5537838,
|
||||
"path": "terminal/mermaid.js"
|
||||
"size": 5537838
|
||||
},
|
||||
{
|
||||
"path": "terminal/terminal.js",
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7",
|
||||
"size": 6627,
|
||||
"path": "terminal/terminal.js"
|
||||
"size": 6627
|
||||
},
|
||||
{
|
||||
"path": "terminal/xterm-LICENSE.txt",
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd",
|
||||
"size": 1261,
|
||||
"path": "terminal/xterm-LICENSE.txt"
|
||||
"size": 1261
|
||||
},
|
||||
{
|
||||
"path": "terminal/xterm.css",
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6",
|
||||
"size": 7112,
|
||||
"path": "terminal/xterm.css"
|
||||
"size": 7112
|
||||
},
|
||||
{
|
||||
"path": "terminal/xterm.js",
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972",
|
||||
"size": 488663,
|
||||
"path": "terminal/xterm.js"
|
||||
"size": 488663
|
||||
},
|
||||
{
|
||||
"path": "LICENSE",
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c",
|
||||
"size": 4401,
|
||||
"path": "LICENSE"
|
||||
"size": 4401
|
||||
},
|
||||
{
|
||||
"path": "json-LICENSE.txt",
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831",
|
||||
"size": 1096,
|
||||
"path": "json-LICENSE.txt"
|
||||
"size": 1096
|
||||
},
|
||||
{
|
||||
"path": "files-text-license.txt",
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625",
|
||||
"size": 883,
|
||||
"path": "files-text-license.txt"
|
||||
"size": 883
|
||||
},
|
||||
{
|
||||
"path": "files-archive-license.txt",
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d",
|
||||
"size": 4990,
|
||||
"path": "files-archive-license.txt"
|
||||
"size": 4990
|
||||
},
|
||||
{
|
||||
"path": "files-image-license.txt",
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4",
|
||||
"size": 3044,
|
||||
"path": "files-image-license.txt"
|
||||
"size": 3044
|
||||
},
|
||||
{
|
||||
"path": "files-sftp-license.txt",
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594",
|
||||
"size": 2064,
|
||||
"path": "files-sftp-license.txt"
|
||||
"size": 2064
|
||||
},
|
||||
{
|
||||
"sha256": "a71afa4f0c1bd4d676b5fc261f1e5436752f6a1af3ae77068ad35803d615e9e3",
|
||||
"size": 107765,
|
||||
"path": "README.md"
|
||||
"path": "README.md",
|
||||
"sha256": "d9a53cb9190dfde2415df54c131b8bd293efbd627014a4e0976cea717ae855ae",
|
||||
"size": 108205
|
||||
},
|
||||
{
|
||||
"sha256": "4eac1f410e6b544aa45756e24f4fdfe9193c6f732410656160be54ab27a0d7e4",
|
||||
"size": 17245,
|
||||
"path": "LAN-PREVIEW.md"
|
||||
"path": "LAN-PREVIEW.md",
|
||||
"sha256": "46d91a76c4a19acb576f0232bdc1d163302cc21f5fbd8fe26e4f93f72ae9c40d",
|
||||
"size": 17941
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/en.txt",
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9",
|
||||
"size": 732485,
|
||||
"path": "dictionaries/en.txt"
|
||||
"size": 732485
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5",
|
||||
"size": 20566,
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt"
|
||||
"size": 20566
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/README.md",
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311",
|
||||
"size": 2265,
|
||||
"path": "dictionaries/README.md"
|
||||
"size": 2265
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/ru.txt",
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849",
|
||||
"size": 1109134,
|
||||
"path": "dictionaries/ru.txt"
|
||||
"size": 1109134
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/sources.json",
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408",
|
||||
"size": 1280,
|
||||
"path": "dictionaries/sources.json"
|
||||
"size": 1280
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/uk.txt",
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf",
|
||||
"size": 940799,
|
||||
"path": "dictionaries/uk.txt"
|
||||
"size": 940799
|
||||
},
|
||||
{
|
||||
"path": "tools/README.txt",
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a",
|
||||
"size": 993,
|
||||
"path": "tools/README.txt"
|
||||
"size": 993
|
||||
},
|
||||
{
|
||||
"sha256": "500c399c5bfdf0ba6ff61986cf9cb25d32394c2d4ff9e3304884d372fbff435d",
|
||||
"size": 133120,
|
||||
"path": "tools/StayHere.exe"
|
||||
"path": "tools/StayHere.exe",
|
||||
"sha256": "980020501d65b5efe5cd947393a9584e523844ef82ec2aff9cb51f3aea7d68eb",
|
||||
"size": 133120
|
||||
},
|
||||
{
|
||||
"path": "tools/StayHere-README.md",
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413",
|
||||
"size": 2796,
|
||||
"path": "tools/StayHere-README.md"
|
||||
"size": 2796
|
||||
}
|
||||
]
|
||||
],
|
||||
"version": "0.8.15"
|
||||
}
|
||||
@@ -7,6 +7,9 @@ IDI_KSWITCHER_HISTORY ICON "kswitcher-history.ico"
|
||||
IDI_KSWITCHER_SCREENSHOT ICON "kswitcher-screenshot.ico"
|
||||
IDI_KSWITCHER_HELP ICON "kswitcher-help.ico"
|
||||
IDI_KSWITCHER_DONATE ICON "kswitcher-donate.ico"
|
||||
#define NAVIGATION_ICON(name, id, file) id ICON file
|
||||
#include "navigation_icons.inc"
|
||||
#undef NAVIGATION_ICON
|
||||
#ifdef KS_SCREENSHOT_RESOURCES
|
||||
IDI_SCREENSHOT_QUESTION ICON "icons/question.ico"
|
||||
IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
|
||||
@@ -14,8 +17,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
|
||||
1 RT_MANIFEST "app.manifest"
|
||||
201 RCDATA "update.ps1"
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 0,8,10,0
|
||||
PRODUCTVERSION 0,8,10,0
|
||||
FILEVERSION 0,8,15,0
|
||||
PRODUCTVERSION 0,8,15,0
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
BEGIN
|
||||
@@ -25,7 +28,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
|
||||
VALUE "ProductName", "KSwitcher"
|
||||
VALUE "FileVersion", "0.8.10"
|
||||
VALUE "FileVersion", "0.8.15"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
@@ -0,0 +1,40 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 120" fill="none" stroke="#000" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round">
|
||||
<g id="Gear" transform="translate(0 0)"><circle cx="12" cy="12" r="3"/><path d="m10 3-.6 2.4-2 .9-2.2-1.2-2 3.5L5 10.3v3.4l-1.8 1.7 2 3.5 2.2-1.2 2 .9.6 2.4h4l.6-2.4 2-.9 2.2 1.2 2-3.5-1.8-1.7v-3.4l1.8-1.7-2-3.5-2.2 1.2-2-.9L14 3z"/></g>
|
||||
<g id="Check" transform="translate(24 0)"><path d="m3 15 3 3 6-7M13 18h8M3 6h9m3 0h6"/></g>
|
||||
<g id="Book" transform="translate(48 0)"><path d="M4 19V5a2 2 0 0 1 2-2h13v18H6a2 2 0 0 1 0-4h13M8 7h7M8 10h5"/></g>
|
||||
<g id="Ban" transform="translate(72 0)"><circle cx="12" cy="12" r="9"/><path d="m6 6 12 12"/></g>
|
||||
<g id="Personal" transform="translate(96 0)"><path d="M4 19V5a2 2 0 0 1 2-2h13v18H6a2 2 0 0 1 0-4h13M8 13c0-3 7-3 7 0"/><circle cx="11.5" cy="7.5" r="1.5"/></g>
|
||||
<g id="Bounds" transform="translate(120 0)"><path d="M7 4H4v16h3m10-16h3v16h-3M8 12h8m-1-1 1 1-1 1m-6-2-1 1 1 1"/></g>
|
||||
<g id="Replace" transform="translate(144 0)"><path d="M3 7h17m-4-4 4 4-4 4m5 6H4m4-4-4 4 4 4"/></g>
|
||||
<g id="Globe" transform="translate(168 0)"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c5 5 5 13 0 18-5-5-5-13 0-18z"/></g>
|
||||
<g id="Chat" transform="translate(0 24)"><path d="M4 5h16v11H9l-5 4zM8 13l2.5-5 2.5 5m-4-1.5h3m3-.5h2"/></g>
|
||||
<g id="Keyboard" transform="translate(24 24)"><rect x="2" y="5" width="20" height="14" rx="2"/><path d="M6 9h.01M10 9h.01M14 9h.01M18 9h.01M6 13h.01M10 13h.01M14 13h.01M18 13h.01M8 16h8"/></g>
|
||||
<g id="Command" transform="translate(48 24)"><path d="M9 9V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3z"/></g>
|
||||
<g id="Clip" transform="translate(72 24)"><rect x="8" y="3" width="8" height="4" rx="1"/><path d="M8 5H5v16h14V5h-3M8 12h8m-8 4h6"/></g>
|
||||
<g id="Scan" transform="translate(96 24)"><path d="M8 3H3v5m13-5h5v5m0 8v5h-5M3 16v5h5m-1-12h10M7 12h10M7 15h6"/></g>
|
||||
<g id="Snippet" transform="translate(120 24)"><path d="M5 3h10l4 4v14H5zM14 3v5h5m-9 4-2 2 2 2m4-4 2 2-2 2"/></g>
|
||||
<g id="Mouse" transform="translate(144 24)"><rect x="6" y="3" width="12" height="18" rx="6"/><path d="M12 3v6"/></g>
|
||||
<g id="Sync" transform="translate(168 24)"><path d="M20 10a8 8 0 0 0-14-4L3 9m0-5v5h5m-4 5a8 8 0 0 0 14 4l3-3m0 5v-5h-5"/></g>
|
||||
<g id="Vault" transform="translate(0 48)"><rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10V7a4 4 0 1 1 8 0v3m-4 5v2"/></g>
|
||||
<g id="Drive" transform="translate(24 48)"><path d="M8 4h7l7 12-4 5H6l-4-5zm0 0 7 12h7M2 16h13l3 5"/></g>
|
||||
<g id="Computers" transform="translate(48 48)"><rect x="2" y="4" width="14" height="11" rx="1"/><path d="M6 19h6m-3-4v4m7-9h6v10h-5m2-3h.01"/></g>
|
||||
<g id="Manage" transform="translate(72 48)"><rect x="2" y="4" width="17" height="12" rx="1"/><path d="M10 16v4m-4 0h8m3-8h5m-2.5-2.5v5"/></g>
|
||||
<g id="Pulse" transform="translate(96 48)"><path d="M2 12h5l3-7 4 14 3-7h5"/></g>
|
||||
<g id="Connect" transform="translate(120 48)"><path d="m9 7 4-4m4 8 4-4m-10-2 8 8m-2-2-5 5a4 4 0 0 1-6-6l5-5M7 15l-4 6"/></g>
|
||||
<g id="Pause" transform="translate(144 48)"><rect x="5" y="4" width="4" height="16" rx="1"/><rect x="15" y="4" width="4" height="16" rx="1"/></g>
|
||||
<g id="Reset" transform="translate(168 48)"><path d="M3 5v5h5m-5 0a9 9 0 1 1 1 7m8-9v4l3 2"/></g>
|
||||
<g id="History" transform="translate(0 72)"><path d="M8 5H5v16h14V5h-3"/><rect x="8" y="3" width="8" height="4" rx="1"/><path d="M12 10v4l3 2"/></g>
|
||||
<g id="Capture" transform="translate(24 72)"><path d="M8 3H3v5m13-5h5v5m0 8v5h-5M3 16v5h5"/><circle cx="12" cy="12" r="3"/></g>
|
||||
<g id="Folder" transform="translate(48 72)"><path d="M3 6h7l2 2h9v12H3z"/></g>
|
||||
<g id="Tools" transform="translate(72 72)"><path d="M21 5a5 5 0 0 1-6 7L7 20a2 2 0 0 1-3-3l8-8a5 5 0 0 1 7-6l-3 3 2 2z"/></g>
|
||||
<g id="Sun" transform="translate(96 72)"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1.5 1.5m11 11L19 19M5 19l1.5-1.5m11-11L19 5"/></g>
|
||||
<g id="ClipPause" transform="translate(120 72)"><path d="M8 5H5v16h14V5h-3M10 11v6m4-6v6"/><rect x="8" y="3" width="8" height="4" rx="1"/></g>
|
||||
<g id="FolderOpen" transform="translate(144 72)"><path d="M3 19V5h7l2 2h8v4M3 19l4-8h15l-4 8z"/></g>
|
||||
<g id="Log" transform="translate(168 72)"><path d="M5 3h10l4 4v14H5zM14 3v5h5M8 12h8m-8 4h8"/></g>
|
||||
<g id="Update" transform="translate(0 96)"><path d="M12 3v12m-4-4 4 4 4-4M4 16v5h16v-5"/></g>
|
||||
<g id="Coffee" transform="translate(24 96)"><path d="M4 6h12v5a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5zm12 1h2a2 2 0 1 1 0 4h-2M3 20h17"/></g>
|
||||
<g id="Help" transform="translate(48 96)"><circle cx="12" cy="12" r="9"/><path d="M9 9a3 3 0 1 1 4 2.8c-1 .4-1 1.2-1 2.2m0 3h.01"/></g>
|
||||
<g id="Exit" transform="translate(72 96)"><path d="M11 4H4v16h7m-1-8h11m-4-4 4 4-4 4"/></g>
|
||||
<g id="Search" transform="translate(96 96)"><circle cx="10.5" cy="10.5" r="5.5"/><path d="m15 15 4 4"/></g>
|
||||
<g id="Play" transform="translate(120 96)"><path d="M7 4l13 8-13 8z"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
@@ -0,0 +1,38 @@
|
||||
NAVIGATION_ICON(Gear, 700, "icons/navigation/gear.ico")
|
||||
NAVIGATION_ICON(Check, 701, "icons/navigation/check.ico")
|
||||
NAVIGATION_ICON(Book, 702, "icons/navigation/book.ico")
|
||||
NAVIGATION_ICON(Ban, 703, "icons/navigation/ban.ico")
|
||||
NAVIGATION_ICON(Personal, 704, "icons/navigation/personal.ico")
|
||||
NAVIGATION_ICON(Bounds, 705, "icons/navigation/bounds.ico")
|
||||
NAVIGATION_ICON(Replace, 706, "icons/navigation/replace.ico")
|
||||
NAVIGATION_ICON(Globe, 707, "icons/navigation/globe.ico")
|
||||
NAVIGATION_ICON(Chat, 708, "icons/navigation/chat.ico")
|
||||
NAVIGATION_ICON(Keyboard, 709, "icons/navigation/keyboard.ico")
|
||||
NAVIGATION_ICON(Command, 710, "icons/navigation/command.ico")
|
||||
NAVIGATION_ICON(Clip, 711, "icons/navigation/clip.ico")
|
||||
NAVIGATION_ICON(Scan, 712, "icons/navigation/scan.ico")
|
||||
NAVIGATION_ICON(Snippet, 713, "icons/navigation/snippet.ico")
|
||||
NAVIGATION_ICON(Mouse, 714, "icons/navigation/mouse.ico")
|
||||
NAVIGATION_ICON(Sync, 715, "icons/navigation/sync.ico")
|
||||
NAVIGATION_ICON(Vault, 716, "icons/navigation/vault.ico")
|
||||
NAVIGATION_ICON(Drive, 717, "icons/navigation/drive.ico")
|
||||
NAVIGATION_ICON(Computers, 718, "icons/navigation/computers.ico")
|
||||
NAVIGATION_ICON(Manage, 719, "icons/navigation/manage.ico")
|
||||
NAVIGATION_ICON(Pulse, 720, "icons/navigation/pulse.ico")
|
||||
NAVIGATION_ICON(Connect, 721, "icons/navigation/connect.ico")
|
||||
NAVIGATION_ICON(Pause, 722, "icons/navigation/pause.ico")
|
||||
NAVIGATION_ICON(Reset, 723, "icons/navigation/reset.ico")
|
||||
NAVIGATION_ICON(History, 724, "icons/navigation/history.ico")
|
||||
NAVIGATION_ICON(Capture, 725, "icons/navigation/capture.ico")
|
||||
NAVIGATION_ICON(Folder, 726, "icons/navigation/folder.ico")
|
||||
NAVIGATION_ICON(Tools, 727, "icons/navigation/tools.ico")
|
||||
NAVIGATION_ICON(Sun, 728, "icons/navigation/sun.ico")
|
||||
NAVIGATION_ICON(ClipPause, 729, "icons/navigation/clippause.ico")
|
||||
NAVIGATION_ICON(FolderOpen, 730, "icons/navigation/folderopen.ico")
|
||||
NAVIGATION_ICON(Log, 731, "icons/navigation/log.ico")
|
||||
NAVIGATION_ICON(Update, 732, "icons/navigation/update.ico")
|
||||
NAVIGATION_ICON(Coffee, 733, "icons/navigation/coffee.ico")
|
||||
NAVIGATION_ICON(Help, 734, "icons/navigation/help.ico")
|
||||
NAVIGATION_ICON(Exit, 735, "icons/navigation/exit.ico")
|
||||
NAVIGATION_ICON(Search, 736, "icons/navigation/search.ico")
|
||||
NAVIGATION_ICON(Play, 737, "icons/navigation/play.ico")
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../resources/resource.h"
|
||||
#include "ocr.h"
|
||||
#include "lan_clipboard_image.h"
|
||||
#include "lan_input.h"
|
||||
#include "lan_files.h"
|
||||
#include "configuration.h"
|
||||
#include "google_drive.h"
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "paste_probe.h"
|
||||
#include "utilities.h"
|
||||
#include "screenshot_notifications.h"
|
||||
#include "navigation_icons.h"
|
||||
#include <algorithm>
|
||||
#include <commctrl.h>
|
||||
#include <set>
|
||||
@@ -226,6 +228,7 @@ ULONG_PTR snippetReplayMarker()
|
||||
}
|
||||
constexpr int OpenFiles = 25, FilesHotkeyFirst = 0x4B10, FilesHotkeySecond = 0x4B11;
|
||||
constexpr int ToggleInputProcessing = 26, DonateViaMonobank = 27, OpenHelp = 28, OpenWhatsNew = 29, OpenAbout = 16;
|
||||
constexpr int ResetHeldInput = 30;
|
||||
constexpr wchar_t MonobankDonationUrl[] = L"https://send.monobank.ua/jar/88h2TddKfS";
|
||||
constexpr int ShortcutProbeId = FilesHotkeySecond + 1;
|
||||
constexpr int FirstCustomShortcut = 0x5000;
|
||||
@@ -1049,51 +1052,37 @@ constexpr UINT TrayInputPulseMs = 450;
|
||||
|
||||
namespace
|
||||
{
|
||||
HBITMAP trayIconBitmap(HICON base, int width, int height, void **data = nullptr)
|
||||
{
|
||||
if (!base || width < 1 || height < 1) return nullptr;
|
||||
BITMAPINFO bitmapInfo{};
|
||||
bitmapInfo.bmiHeader = {sizeof(BITMAPINFOHEADER), width, -height, 1, 32, BI_RGB};
|
||||
void *bits{};
|
||||
HBITMAP bitmap = CreateDIBSection(nullptr, &bitmapInfo, DIB_RGB_COLORS, &bits, nullptr, 0);
|
||||
if (!bitmap) return nullptr;
|
||||
HDC dc = CreateCompatibleDC(nullptr);
|
||||
BOOL drawn = FALSE;
|
||||
if (dc)
|
||||
{
|
||||
auto previous = SelectObject(dc, bitmap);
|
||||
std::fill_n(static_cast<uint32_t *>(bits), size_t(width) * height, 0);
|
||||
drawn = DrawIconEx(dc, 0, 0, base, width, height, 0, nullptr, DI_NORMAL);
|
||||
GdiFlush();
|
||||
SelectObject(dc, previous);
|
||||
DeleteDC(dc);
|
||||
}
|
||||
if (drawn)
|
||||
{
|
||||
if (data) *data = bits;
|
||||
return bitmap;
|
||||
}
|
||||
DeleteObject(bitmap);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HICON trayInputIcon(HICON base, int width, int height, uint32_t color)
|
||||
HICON trayInputIcon(HICON base, int width, int height, uint32_t color, bool blocked = false)
|
||||
{
|
||||
if (width < 8 || height < 8) return nullptr;
|
||||
void *bits{};
|
||||
const auto bitmap = trayIconBitmap(base, width, height, &bits);
|
||||
const auto bitmap = iconBitmap(base, width, height, &bits);
|
||||
if (!bitmap) return nullptr;
|
||||
auto pixels = static_cast<uint32_t *>(bits);
|
||||
const int radius = std::max(3, MulDiv(std::min(width, height), 3, 16));
|
||||
const int minimumRadius = blocked ? 4 : 3;
|
||||
const int radius = std::min((std::min(width, height) - 1) / 2,
|
||||
std::max(minimumRadius, MulDiv(std::min(width, height), minimumRadius, 16)));
|
||||
const int cx = width - 1 - radius, cy = height - 1 - radius;
|
||||
constexpr uint32_t ink = 0xff242424;
|
||||
for (int y = -radius; y <= radius; ++y)
|
||||
for (int x = -radius; x <= radius; ++x)
|
||||
{
|
||||
const int distance = x * x + y * y;
|
||||
if (distance <= radius * radius)
|
||||
pixels[(cy + y) * width + cx + x] = distance <= (radius - 1) * (radius - 1)
|
||||
? color : 0xff242424;
|
||||
? color : ink;
|
||||
}
|
||||
if (blocked)
|
||||
{
|
||||
const int stroke = std::max(1, radius / 4);
|
||||
const int left = cx - (stroke - 1) / 2;
|
||||
const int dot = cy + std::max(2, radius / 2);
|
||||
for (int x = left; x < left + stroke; ++x)
|
||||
{
|
||||
for (int y = cy - radius / 2; y <= cy; ++y) pixels[y * width + x] = ink;
|
||||
for (int y = dot; y < dot + stroke; ++y) pixels[y * width + x] = ink;
|
||||
}
|
||||
}
|
||||
// The 32-bit DIB supplies the transparency. The fallback mask is initialized as well.
|
||||
std::vector<unsigned char> maskBits(size_t((width + 15) / 16) * 2 * height);
|
||||
HICON icon{};
|
||||
@@ -1114,6 +1103,16 @@ HICON App::trayBaseIcon(int width, int height) const
|
||||
return static_cast<HICON>(LoadImageW(instance, MAKEINTRESOURCEW(resource), IMAGE_ICON, width, height, LR_SHARED));
|
||||
}
|
||||
|
||||
HICON App::trayInputBadge(HICON base, int width, int height) const
|
||||
{
|
||||
if (inputState != InputState::Active) return nullptr;
|
||||
if (!trayInputBlock.empty()) return trayInputIcon(base, width, height, 0xffffc457, true);
|
||||
if (!trayInput.paired) return nullptr;
|
||||
const uint32_t color = trayInput.stopped ? 0xfff16b66 : !trayInput.online ? 0xffa0a4ab :
|
||||
!trayInput.reconnecting() ? 0xff45d58c : trayInputPulse ? 0xffffc457 : 0xffac7830;
|
||||
return trayInputIcon(base, width, height, color);
|
||||
}
|
||||
|
||||
bool App::updateTray(DWORD action)
|
||||
{
|
||||
NOTIFYICONDATAW icon{sizeof(icon)};
|
||||
@@ -1124,7 +1123,8 @@ bool App::updateTray(DWORD action)
|
||||
icon.uCallbackMessage = TrayMessage;
|
||||
const int width = GetSystemMetrics(SM_CXSMICON), height = GetSystemMetrics(SM_CYSMICON);
|
||||
icon.hIcon = trayBaseIcon(width, height);
|
||||
HICON badge{};
|
||||
const auto badge = trayInputBadge(icon.hIcon, width, height);
|
||||
if (badge) icon.hIcon = badge;
|
||||
auto tip = localBuildTitle(L"KSwitcher");
|
||||
const auto state = inputState.load();
|
||||
tip += state == InputState::Active ? L" — Input processing active" :
|
||||
@@ -1132,10 +1132,6 @@ bool App::updateTray(DWORD action)
|
||||
if (state == InputState::Active && trayInput.paired)
|
||||
{
|
||||
const bool reconnecting = trayInput.reconnecting();
|
||||
const uint32_t color = trayInput.stopped ? 0xfff16b66 : !trayInput.online ? 0xffa0a4ab :
|
||||
!reconnecting ? 0xff45d58c : trayInputPulse ? 0xffffc457 : 0xffac7830;
|
||||
badge = trayInputIcon(icon.hIcon, width, height, color);
|
||||
if (badge) icon.hIcon = badge;
|
||||
tip += L"\nMouse & keyboard: ";
|
||||
if (trayInput.stopped) tip += L"connection stopped";
|
||||
else if (!trayInput.online) tip += L"all paired PCs offline. Waiting for LAN discovery.";
|
||||
@@ -1147,6 +1143,7 @@ bool App::updateTray(DWORD action)
|
||||
std::to_wstring(trayInput.paired) + L" PCs connected)";
|
||||
}
|
||||
}
|
||||
if (state == InputState::Active && !trayInputBlock.empty()) tip = trayInputBlock;
|
||||
wcsncpy_s(icon.szTip, tip.c_str(), _TRUNCATE);
|
||||
const bool updated = Shell_NotifyIconW(action, &icon) != FALSE;
|
||||
if (badge) DestroyIcon(badge);
|
||||
@@ -1155,6 +1152,7 @@ bool App::updateTray(DWORD action)
|
||||
|
||||
void App::refreshTrayInput()
|
||||
{
|
||||
refreshTrayInputBlock();
|
||||
const auto state = lanService ? lanService->inputConnections() : LanInputConnections{};
|
||||
if (state == trayInput) return;
|
||||
trayInput = state;
|
||||
@@ -1166,6 +1164,41 @@ void App::refreshTrayInput()
|
||||
updateTray(NIM_MODIFY);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool trayNotice(HWND window, const std::wstring &text)
|
||||
{
|
||||
NOTIFYICONDATAW icon{sizeof(icon)};
|
||||
icon.hWnd = window;
|
||||
icon.uID = 1;
|
||||
icon.uFlags = NIF_INFO;
|
||||
wcsncpy_s(icon.szInfo, text.c_str(), _TRUNCATE);
|
||||
wcscpy_s(icon.szInfoTitle, L"KSwitcher");
|
||||
icon.dwInfoFlags = NIIF_WARNING;
|
||||
return Shell_NotifyIconW(NIM_MODIFY, &icon) != FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void App::refreshTrayInputBlock()
|
||||
{
|
||||
auto block = lanService ? lanService->inputBlockText() : std::wstring{};
|
||||
if (block == trayInputBlock) return;
|
||||
const bool newlyBlocked = trayInputBlock.empty();
|
||||
trayInputBlock = std::move(block);
|
||||
updateTray(NIM_MODIFY);
|
||||
const auto now = GetTickCount64();
|
||||
if (newlyBlocked && now >= nextInputBlockNotice)
|
||||
{
|
||||
inputBlockNoticeVisible = trayNotice(window, trayInputBlock);
|
||||
nextInputBlockNotice = now + 4000;
|
||||
}
|
||||
else if (inputBlockNoticeVisible)
|
||||
{
|
||||
trayNotice(window, {});
|
||||
inputBlockNoticeVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void App::addTray()
|
||||
{
|
||||
if (updateTray(NIM_ADD))
|
||||
@@ -1234,13 +1267,18 @@ bool App::registerHotkeys(const Settings &s, bool rollback)
|
||||
return true;
|
||||
}
|
||||
|
||||
void App::startLanService()
|
||||
{
|
||||
lanService = std::make_unique<LanService>(data, window, inputState != InputState::Active, [this] {
|
||||
// Mouse actions may consume a button press before it reaches Windows.
|
||||
const auto held = std::find_if(mousePresses.begin(), mousePresses.end(), [](const auto &press) { return press.held; });
|
||||
return held == mousePresses.end() ? 0 : lan::MouseInputKeys[size_t(held - mousePresses.begin())];
|
||||
});
|
||||
if (!smoke) lanService->startClients();
|
||||
}
|
||||
Bytes App::lanCommand(const Bytes &command)
|
||||
{
|
||||
if (!lanService)
|
||||
{
|
||||
lanService = std::make_unique<LanService>(data,window,inputState != InputState::Active);
|
||||
if (!smoke) lanService->startClients();
|
||||
}
|
||||
if (!lanService) startLanService();
|
||||
auto reply = lanService->command(command);
|
||||
updateLanInputTimer();
|
||||
if (lanService->takeInputChange()) resetLanInput();
|
||||
@@ -1254,9 +1292,14 @@ void App::updateLanInputTimer()
|
||||
}
|
||||
void App::pollLanInput()
|
||||
{
|
||||
// Temporary text transactions only block new handoffs. A tray pause removes
|
||||
// the router entirely, including for already queued network notifications.
|
||||
if (lanService && lanService->tickInput(!busy && !suspended && !hotkeyCapture)) resetLanInput();
|
||||
// Keep new handoffs and remote resets out of text transactions and shortcut capture.
|
||||
// Pausing in the tray also removes the input router.
|
||||
const bool allowInputRequest = !busy && !suspended && !hotkeyCapture;
|
||||
if (lanService && lanService->tickInput(allowInputRequest, [this] {
|
||||
if (!busy && !suspended && !hotkeyCapture && !installingUpdate && !resetHeldInput())
|
||||
log(L"LAN input: could not reset held input on this PC");
|
||||
})) resetLanInput();
|
||||
refreshTrayInputBlock();
|
||||
}
|
||||
void App::applySettings(const Settings &requested, const Bytes &supplement)
|
||||
{
|
||||
@@ -2330,6 +2373,8 @@ LRESULT CALLBACK App::mouseProc(int code, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
auto &app = *current;
|
||||
const auto &mouse = *reinterpret_cast<const MSLLHOOKSTRUCT *>(lp);
|
||||
if ((mouse.flags & LLMHF_INJECTED) && mouse.dwExtraInfo == inputMarker())
|
||||
return CallNextHookEx(nullptr, code, wp, lp);
|
||||
// Forwarded mouse events use the same bindings as local events on this PC.
|
||||
const int button = mouseButton(UINT(wp), HIWORD(mouse.mouseData));
|
||||
const auto wheelDelta = static_cast<SHORT>(HIWORD(mouse.mouseData));
|
||||
@@ -2358,10 +2403,8 @@ LRESULT CALLBACK App::mouseProc(int code, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
if (app.lanService)
|
||||
{
|
||||
const bool mouseActionHeld = std::any_of(app.mousePresses.begin(), app.mousePresses.end(),
|
||||
[](const MousePress &press) { return press.held; });
|
||||
bool consumed = app.lanService->mouse(UINT(wp), mouse,
|
||||
!app.busy && !app.suspended && !app.hotkeyCapture && !mouseActionHeld);
|
||||
!app.busy && !app.suspended && !app.hotkeyCapture);
|
||||
if (app.lanService->takeInputChange()) app.resetLanInput();
|
||||
if (consumed) return 1;
|
||||
}
|
||||
@@ -3349,6 +3392,23 @@ void App::recognizeEntry(std::wstring id)
|
||||
}
|
||||
});
|
||||
}
|
||||
void App::clearMousePresses()
|
||||
{
|
||||
mousePresses = {};
|
||||
pendingMouseClicks = {};
|
||||
KillTimer(window, MouseClickTimer);
|
||||
for (size_t i = 0; i < mousePresses.size(); ++i) KillTimer(window, FirstMouseVolumeTimer + i);
|
||||
PostMessageW(window, MouseVolumeReleasedMessage, 0, 0);
|
||||
}
|
||||
|
||||
bool App::resetHeldInput()
|
||||
{
|
||||
if (!lan::resetWindowsHeldInput()) return false;
|
||||
if (lanService) lanService->forgetHeldInput();
|
||||
clearMousePresses();
|
||||
return true;
|
||||
}
|
||||
|
||||
void App::toggleInputProcessing()
|
||||
{
|
||||
if (inputState == InputState::Pausing) return;
|
||||
@@ -3362,10 +3422,7 @@ void App::toggleInputProcessing()
|
||||
if (shortcutAvailable(window, binding.second)) availableBeforePause.push_back(binding.second);
|
||||
releaseInputHooks();
|
||||
resetLanInput();
|
||||
mousePresses = {};
|
||||
KillTimer(window, MouseClickTimer);
|
||||
for (size_t i = 0; i < mousePresses.size(); ++i) KillTimer(window, FirstMouseVolumeTimer + i);
|
||||
PostMessageW(window, MouseVolumeReleasedMessage, 0, 0);
|
||||
clearMousePresses();
|
||||
hideSnippetPopup();
|
||||
if (lanService) lanService->setInputPaused(true);
|
||||
KillTimer(window, 8);
|
||||
@@ -3415,64 +3472,77 @@ void App::trayMenu()
|
||||
auto utilities = discoverUtilities(std::filesystem::path(executable()).parent_path() / L"tools", utilitiesError);
|
||||
if (utilities.size() > 50000) utilities.resize(50000);
|
||||
HMENU menu = CreatePopupMenu();
|
||||
AppendMenuW(menu, MF_STRING | (inputState == InputState::Pausing ? MF_GRAYED : 0), ToggleInputProcessing,
|
||||
POINT pt{};
|
||||
GetCursorPos(&pt);
|
||||
const int iconSize = MulDiv(16, GetDpiForWindow(window), USER_DEFAULT_SCREEN_DPI);
|
||||
HIGHCONTRASTW contrast{sizeof(contrast)};
|
||||
const bool highContrast = SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(contrast), &contrast, 0) &&
|
||||
(contrast.dwFlags & HCF_HIGHCONTRASTON);
|
||||
std::vector<HBITMAP> bitmaps;
|
||||
bitmaps.reserve(17);
|
||||
const auto append = [&](NavigationIcon icon, UINT flags, UINT_PTR command, const wchar_t *label)
|
||||
{
|
||||
if (!AppendMenuW(menu, flags, command, label)) return;
|
||||
const COLORREF color = flags & MF_GRAYED ? GetSysColor(COLOR_GRAYTEXT) :
|
||||
highContrast ? GetSysColor(COLOR_MENUTEXT) :
|
||||
icon == NavigationIcon::Gear || icon == NavigationIcon::Coffee ? NavigationIconAccent : NavigationIconColor;
|
||||
if (const auto bitmap = navigationIconBitmap(instance, icon, iconSize, color))
|
||||
{
|
||||
bitmaps.push_back(bitmap);
|
||||
MENUITEMINFOW item{sizeof(item), MIIM_BITMAP};
|
||||
item.hbmpItem = bitmap;
|
||||
SetMenuItemInfoW(menu, GetMenuItemCount(menu) - 1, TRUE, &item);
|
||||
}
|
||||
};
|
||||
const auto inputIcon = inputState == InputState::Paused ? NavigationIcon::Play : NavigationIcon::Pause;
|
||||
append(inputIcon, MF_STRING | (inputState == InputState::Pausing ? MF_GRAYED : 0), ToggleInputProcessing,
|
||||
inputState == InputState::Active ? L"Pause &input processing" :
|
||||
inputState == InputState::Paused ? L"Resume &input processing" : L"Pausing input processing…");
|
||||
append(NavigationIcon::Reset, MF_STRING, ResetHeldInput, PRIMARYLANGID(GetThreadUILanguage()) == LANG_UKRAINIAN ?
|
||||
L"Скинути затиснуті клавіші й кнопки миші" : L"Reset held keys and mouse buttons");
|
||||
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
AppendMenuW(menu, MF_STRING, 10, L"Clipboard &history");
|
||||
AppendMenuW(menu, MF_STRING, 24, L"&Capture screen region…");
|
||||
AppendMenuW(menu, MF_STRING, 11, L"&Settings…");
|
||||
AppendMenuW(menu, MF_STRING, OpenFiles, L"&Files…");
|
||||
append(NavigationIcon::History, MF_STRING, 10, L"Clipboard &history");
|
||||
append(NavigationIcon::Capture, MF_STRING, 24, L"&Capture screen region…");
|
||||
append(NavigationIcon::Gear, MF_STRING, 11, L"&Settings…");
|
||||
append(NavigationIcon::Folder, MF_STRING, OpenFiles, L"&Files…");
|
||||
SetMenuDefaultItem(menu, 11, FALSE);
|
||||
AppendMenuW(menu, MF_STRING, 12, L"S&nippets…");
|
||||
AppendMenuW(menu, MF_STRING, 13, L"&Keyboard shortcuts…");
|
||||
append(NavigationIcon::Snippet, MF_STRING, 12, L"S&nippets…");
|
||||
append(NavigationIcon::Keyboard, MF_STRING, 13, L"&Keyboard shortcuts…");
|
||||
HMENU utilityMenu = CreatePopupMenu();
|
||||
for (size_t i = 0; i < utilities.size(); ++i)
|
||||
AppendMenuW(utilityMenu, MF_STRING, utilityCommandBase + i, utilityMenuLabel(utilities[i]).c_str());
|
||||
if (utilities.empty())
|
||||
AppendMenuW(utilityMenu, MF_STRING | MF_GRAYED, 0,
|
||||
utilitiesError ? L"Cannot read tools folder" : L"No utilities in tools folder");
|
||||
AppendMenuW(menu, MF_POPUP, (UINT_PTR)utilityMenu, L"&Tools");
|
||||
append(NavigationIcon::Tools, MF_POPUP, (UINT_PTR)utilityMenu, L"&Tools");
|
||||
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
AppendMenuW(menu, MF_STRING | (settings.awake ? MF_CHECKED : 0), 14, L"Keep screen a&wake");
|
||||
append(NavigationIcon::Sun, MF_STRING | (settings.awake ? MF_CHECKED : 0), 14, L"Keep screen a&wake");
|
||||
HMENU pause = CreatePopupMenu();
|
||||
AppendMenuW(pause, MF_STRING, 20, L"&Resume");
|
||||
AppendMenuW(pause, MF_STRING, 21, L"&10 minutes");
|
||||
AppendMenuW(pause, MF_STRING, 22, L"1 &hour");
|
||||
AppendMenuW(pause, MF_STRING, 23, L"&Until restart");
|
||||
AppendMenuW(menu, MF_POPUP, (UINT_PTR)pause, L"&Pause clipboard history");
|
||||
AppendMenuW(menu, MF_STRING, 15, L"&Open data folder");
|
||||
AppendMenuW(menu, MF_STRING, 18, L"View &log…");
|
||||
AppendMenuW(menu, MF_STRING | (updateRunning ? MF_GRAYED : 0), 19,
|
||||
append(NavigationIcon::ClipPause, MF_POPUP, (UINT_PTR)pause, L"&Pause clipboard history");
|
||||
append(NavigationIcon::FolderOpen, MF_STRING, 15, L"&Open data folder");
|
||||
append(NavigationIcon::Log, MF_STRING, 18, L"View &log…");
|
||||
append(NavigationIcon::Update, MF_STRING | (updateRunning ? MF_GRAYED : 0), 19,
|
||||
updateRunning ? L"&Update (checking / preparing…)" :
|
||||
availableUpdate.empty() ? L"&Update" : L"&Update (new version available)");
|
||||
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
AppendMenuW(menu, MF_STRING, DonateViaMonobank, L"&Donate via Monobank");
|
||||
const int iconSize = MulDiv(16, GetDpiForWindow(window), 96);
|
||||
const auto donateIcon = static_cast<HICON>(LoadImageW(instance, MAKEINTRESOURCEW(IDI_KSWITCHER_DONATE),
|
||||
IMAGE_ICON, iconSize, iconSize, LR_SHARED));
|
||||
const auto donateBitmap = trayIconBitmap(donateIcon, iconSize, iconSize);
|
||||
if (donateBitmap)
|
||||
{
|
||||
MENUITEMINFOW item{sizeof(item), MIIM_BITMAP};
|
||||
item.hbmpItem = donateBitmap;
|
||||
SetMenuItemInfoW(menu, DonateViaMonobank, FALSE, &item);
|
||||
}
|
||||
append(NavigationIcon::Coffee, MF_STRING, DonateViaMonobank, L"&Donate via Monobank");
|
||||
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
HMENU help = CreatePopupMenu();
|
||||
AppendMenuW(help, MF_STRING, OpenHelp, L"&User guide");
|
||||
AppendMenuW(help, MF_STRING, OpenWhatsNew, whatsNewTitle(GetThreadUILanguage()));
|
||||
AppendMenuW(help, MF_STRING, OpenAbout, L"&About KSwitcher");
|
||||
AppendMenuW(menu, MF_POPUP, reinterpret_cast<UINT_PTR>(help), L"H&elp");
|
||||
AppendMenuW(menu, MF_STRING, 17, L"E&xit");
|
||||
POINT pt{};
|
||||
GetCursorPos(&pt);
|
||||
append(NavigationIcon::Help, MF_POPUP, reinterpret_cast<UINT_PTR>(help), L"H&elp");
|
||||
append(NavigationIcon::Exit, MF_STRING, 17, L"E&xit");
|
||||
pasteTarget = GetForegroundWindow();
|
||||
SetForegroundWindow(window);
|
||||
showMenuAccessKeys(menu);
|
||||
int cmd = TrackPopupMenu(menu, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, window, nullptr);
|
||||
DestroyMenu(menu);
|
||||
if (donateBitmap) DeleteObject(donateBitmap);
|
||||
for (const auto bitmap : bitmaps) DeleteObject(bitmap);
|
||||
PostMessageW(window, WM_NULL, 0, 0);
|
||||
try
|
||||
{
|
||||
@@ -3495,6 +3565,10 @@ void App::trayMenu()
|
||||
case ToggleInputProcessing:
|
||||
toggleInputProcessing();
|
||||
break;
|
||||
case ResetHeldInput:
|
||||
if (!resetHeldInput()) report(L"Windows could not release all held keys or mouse buttons on this PC.");
|
||||
if (lanService) lanService->requestHeldInputReset();
|
||||
break;
|
||||
case OpenFiles:
|
||||
dispatch(OpenFiles);
|
||||
break;
|
||||
@@ -3731,6 +3805,12 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (app->installingUpdate || app->busy || app->hotkeyCapture || index >= app->settings.customShortcuts.size()) return 0;
|
||||
const auto &rule = app->settings.customShortcuts[index];
|
||||
if (!rule.enabled || Hotkey::parse(rule.shortcut) != Hotkey{LOWORD(lp), HIWORD(lp)}) return 0;
|
||||
if (rule.action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
if (!openShortcutUrl(rule))
|
||||
app->report(L"Could not open the URL for " + rule.name + L". Check the configured browser and profile.");
|
||||
return 0;
|
||||
}
|
||||
if (rule.action == CustomShortcutAction::SendText)
|
||||
{
|
||||
const auto target = shortcutAppWindow(rule.executable, app->recentForegroundWindows);
|
||||
@@ -3846,14 +3926,8 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case ErrorMessage:
|
||||
{
|
||||
std::unique_ptr<std::wstring> text((std::wstring *)lp);
|
||||
NOTIFYICONDATAW icon{sizeof(icon)};
|
||||
icon.hWnd = hwnd;
|
||||
icon.uID = 1;
|
||||
icon.uFlags = NIF_INFO;
|
||||
wcsncpy_s(icon.szInfo, text->c_str(), _TRUNCATE);
|
||||
wcscpy_s(icon.szInfoTitle, L"KSwitcher");
|
||||
icon.dwInfoFlags = NIIF_WARNING;
|
||||
Shell_NotifyIconW(NIM_MODIFY, &icon);
|
||||
app->inputBlockNoticeVisible = false;
|
||||
trayNotice(hwnd, *text);
|
||||
return 0;
|
||||
}
|
||||
case LanInputStatusMessage:
|
||||
@@ -3919,7 +3993,7 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (app->trayInput.reconnecting())
|
||||
{
|
||||
app->trayInputPulse = !app->trayInputPulse;
|
||||
app->updateTray(NIM_MODIFY);
|
||||
if (app->trayInputBlock.empty()) app->updateTray(NIM_MODIFY);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -4106,7 +4180,7 @@ int App::execute()
|
||||
if (!smoke && inputState == InputState::Active) startBrowserChatMonitor();
|
||||
if (!smoke && (std::filesystem::exists(data / L"lan-pairing.bin") ||
|
||||
std::filesystem::exists(data / L"lan-clients.bin")))
|
||||
try { lanService = std::make_unique<LanService>(data,window,inputState != InputState::Active); lanService->startClients(); }
|
||||
try { startLanService(); }
|
||||
catch (const std::exception &e) { report(L"LAN module: " + wide(e.what())); }
|
||||
updateLanInputTimer();
|
||||
refreshTrayInput();
|
||||
|
||||
@@ -126,6 +126,7 @@ class App
|
||||
void toggleInputProcessing();
|
||||
void updateLanInputTimer();
|
||||
void pollLanInput();
|
||||
void startLanService();
|
||||
struct MousePress
|
||||
{
|
||||
HWND target{};
|
||||
@@ -180,9 +181,16 @@ class App
|
||||
bool trayRetryPending{};
|
||||
LanInputConnections trayInput;
|
||||
bool trayInputPulse{};
|
||||
std::wstring trayInputBlock;
|
||||
ULONGLONG nextInputBlockNotice{};
|
||||
bool inputBlockNoticeVisible{};
|
||||
HICON trayBaseIcon(int width, int height) const;
|
||||
HICON trayInputBadge(HICON base, int width, int height) const;
|
||||
bool updateTray(DWORD action);
|
||||
void refreshTrayInput();
|
||||
void refreshTrayInputBlock();
|
||||
void clearMousePresses();
|
||||
bool resetHeldInput();
|
||||
uint64_t transformAttempt{}, previousAttemptVersion{};
|
||||
std::atomic<uint64_t> activeTransformAttempt{};
|
||||
ULONGLONG previousAttemptAt{};
|
||||
|
||||
@@ -82,7 +82,8 @@ struct MouseAction
|
||||
int volumeStep = DefaultMouseVolumeStep;
|
||||
bool operator==(const MouseAction &) const = default;
|
||||
};
|
||||
enum class CustomShortcutAction { LaunchApp, SendText };
|
||||
enum class CustomShortcutAction { LaunchApp, SendText, OpenUrl };
|
||||
enum class ShortcutBrowser { Default, Chrome, Other };
|
||||
struct CustomShortcut
|
||||
{
|
||||
std::wstring name, shortcut, executable;
|
||||
@@ -91,6 +92,9 @@ struct CustomShortcut
|
||||
CustomShortcutAction action = CustomShortcutAction::LaunchApp;
|
||||
std::wstring controlClass, text;
|
||||
int controlId = 0;
|
||||
std::wstring url;
|
||||
ShortcutBrowser browser = ShortcutBrowser::Default;
|
||||
std::wstring chromeProfile;
|
||||
bool operator==(const CustomShortcut &) const = default;
|
||||
};
|
||||
struct Settings
|
||||
|
||||
@@ -148,6 +148,7 @@ struct LanService::Impl
|
||||
std::mutex inputMutex;
|
||||
std::vector<lan::RoutedInput> inputOut,inputIn;
|
||||
std::map<std::string,uint64_t> inputReady;
|
||||
std::function<int()> additionalHeldKey;
|
||||
std::unique_ptr<lan::InputMesh> router;
|
||||
std::string inputStatus="Input sharing disabled.";
|
||||
size_t inputConnectedPeers{}, inputOnlinePeers{};
|
||||
@@ -155,8 +156,8 @@ struct LanService::Impl
|
||||
bool inputNeedsHelp{};
|
||||
HWND inputWindow{};std::atomic<bool> inputNotification{false};
|
||||
lan::LanClients clients;
|
||||
explicit Impl(const std::filesystem::path &root,HWND window,bool paused)
|
||||
: path(root/L"lan-pairing.bin"),inputPaused(paused),inputWindow(window),clients(root)
|
||||
explicit Impl(const std::filesystem::path &root,HWND window,bool paused,std::function<int()> heldKey)
|
||||
: path(root/L"lan-pairing.bin"),inputPaused(paused),additionalHeldKey(std::move(heldKey)),inputWindow(window),clients(root)
|
||||
{
|
||||
if(std::filesystem::exists(path))
|
||||
{
|
||||
@@ -239,7 +240,8 @@ struct LanService::Impl
|
||||
router.reset();++inputConfiguration;
|
||||
if(enabled&&shareInput&&!inputPaused){
|
||||
std::map<std::string,POINT> layout;for(auto &[peer,cell]:positions.items())if(trusted.contains(peer))layout[peer]={cell[0].get<LONG>(),cell[1].get<LONG>()};
|
||||
router=std::make_unique<lan::InputMesh>(id,lan::windowsInputEnvironment(),std::move(layout),[this](const auto &peer,auto f){return queue(peer,f);});
|
||||
router=std::make_unique<lan::InputMesh>(id,lan::windowsInputEnvironment(additionalHeldKey),std::move(layout),
|
||||
[this](const auto &peer,auto f){return queue(peer,f);});
|
||||
}
|
||||
inputStatus=enabled&&shareInput?"Connecting input channels...":"Input sharing disabled.";
|
||||
observedRevision=0;
|
||||
@@ -269,7 +271,7 @@ struct LanService::Impl
|
||||
bool changed=revision!=observedRevision||configuration!=observedConfiguration;
|
||||
observedRevision=revision;observedConfiguration=configuration;return changed;
|
||||
}
|
||||
bool tickInput(bool allowEnter)
|
||||
bool tickInput(bool allowEnter,const std::function<void()> &resetHeldInput)
|
||||
{
|
||||
inputNotification=false;
|
||||
if(layoutChanged.exchange(false)){std::lock_guard lock(mutex);configureRouter();}
|
||||
@@ -278,10 +280,39 @@ struct LanService::Impl
|
||||
std::vector<lan::RoutedInput> incoming;std::map<std::string,uint64_t> ready;
|
||||
{std::lock_guard lock(inputMutex);incoming.swap(inputIn);ready=inputReady;}
|
||||
router->tick(ready,GetTickCount64());
|
||||
for(auto &frame:incoming)if(ready.contains(frame.peer)&&ready.at(frame.peer)==frame.epoch)
|
||||
router->receive(frame.peer,frame.frame,GetTickCount64(),allowEnter);
|
||||
for(auto &frame:incoming)
|
||||
{
|
||||
if(!ready.contains(frame.peer)||ready.at(frame.peer)!=frame.epoch)continue;
|
||||
if(frame.frame==lan::ResetHeldInputRequest)
|
||||
{
|
||||
// A peer may have been forgotten since the transport queued its request.
|
||||
std::lock_guard lock(mutex);
|
||||
if(!trusted.contains(frame.peer))continue;
|
||||
}
|
||||
router->receive(frame.peer,frame.frame,GetTickCount64(),allowEnter,resetHeldInput);
|
||||
}
|
||||
return takeChange();
|
||||
}
|
||||
std::wstring inputBlockText(const lan::HandoffBlock &block) const
|
||||
{
|
||||
if(!block.key)return {};
|
||||
std::wstring location=L"this PC";
|
||||
if(!block.peer.empty())
|
||||
{
|
||||
auto paired=trusted.find(block.peer);
|
||||
if(paired==trusted.end())return {};
|
||||
location=wide(paired->value("name",block.peer.substr(0,8)));
|
||||
if(location.size()>50)
|
||||
{
|
||||
const bool highSurrogate=location[48]>=0xd800&&location[48]<=0xdbff;
|
||||
location.resize(highSurrogate?48:49);
|
||||
location+=L"…";
|
||||
}
|
||||
}
|
||||
auto input=lan::heldInputName(block.key);
|
||||
return L"Cursor handoff blocked on "+location+L": "+
|
||||
(input.empty()?L"a key or mouse button is held.":input+L" is held.");
|
||||
}
|
||||
void start()
|
||||
{
|
||||
stopping=false; epoch=lan::randomHex(16); status="Searching for KSwitcher computers...";
|
||||
@@ -827,6 +858,7 @@ struct LanService::Impl
|
||||
{"positions",positions},{"shareInput",shareInput},{"inputPeer",inputPeer},{"controlPeer",router?router->peer():std::string{}},{"inputEdge",inputEdge},{"inputConnected",inputConnectedPeers!=0},
|
||||
{"inputStatus",inputPaused?"Input processing paused in the tray.":enabled&&shareInput?inputStatus:"Input sharing disabled."},{"inputNeedsHelp",!inputPaused&&enabled&&shareInput&&inputNeedsHelp},{"controlMode",router?int(router->mode()):0}};
|
||||
{std::lock_guard inputLock(inputMutex);result["inputReady"]=inputReady;}
|
||||
result["inputBlock"]=router?utf8(inputBlockText(router->handoffBlock())):std::string{};
|
||||
result["shareLogs"]=shareLogs;
|
||||
result["files"]=Json::array();
|
||||
result["transferStatus"]=transfers->status;
|
||||
@@ -853,7 +885,8 @@ struct LanService::Impl
|
||||
return encoded(result);
|
||||
}
|
||||
};
|
||||
LanService::LanService(const std::filesystem::path &path,HWND window,bool paused) : impl(std::make_unique<Impl>(path,window,paused)) {}
|
||||
LanService::LanService(const std::filesystem::path &path,HWND window,bool paused,std::function<int()> heldKey)
|
||||
:impl(std::make_unique<Impl>(path,window,paused,std::move(heldKey))) {}
|
||||
LanService::~LanService()=default;
|
||||
Bytes LanService::command(const Bytes &command) { return impl->command(command); }
|
||||
void LanService::startClients() { impl->startClients(); }
|
||||
@@ -887,7 +920,26 @@ LanInputConnections LanService::inputConnections()const
|
||||
const auto paired=impl->trusted.size();
|
||||
return {std::min(impl->inputConnectedPeers,paired),std::min(impl->inputOnlinePeers,paired),paired,impl->inputWorkerStopped};
|
||||
}
|
||||
bool LanService::tickInput(bool allowEnter){return impl->tickInput(allowEnter);}
|
||||
bool LanService::tickInput(bool allowEnter,const std::function<void()> &resetHeldInput)
|
||||
{return impl->tickInput(allowEnter,resetHeldInput);}
|
||||
std::wstring LanService::inputBlockText()const
|
||||
{
|
||||
const auto block=impl->router?impl->router->handoffBlock():lan::HandoffBlock{};
|
||||
if(!block.key)return {};
|
||||
std::lock_guard lock(impl->mutex);
|
||||
return impl->inputBlockText(block);
|
||||
}
|
||||
void LanService::forgetHeldInput()
|
||||
{
|
||||
if(!impl->router)return;
|
||||
if(impl->router->mode()!=lan::ControlMode::Local)impl->router->cancel(GetTickCount64());
|
||||
impl->router->forgetHeldKeys();
|
||||
}
|
||||
void LanService::requestHeldInputReset()
|
||||
{
|
||||
std::lock_guard lock(impl->mutex);
|
||||
if(impl->router)impl->router->requestHeldInputReset([this](const auto &peer){return impl->trusted.contains(peer);});
|
||||
}
|
||||
bool LanService::keyboard(const KBDLLHOOKSTRUCT &k,bool down){return impl->router&&impl->router->keyboard(k,down,GetTickCount64());}
|
||||
bool LanService::mouse(UINT message,const MSLLHOOKSTRUCT &m,bool allowEnter){return impl->router&&impl->router->mouse(message,m,GetTickCount64(),allowEnter);}
|
||||
bool LanService::takeInputChange(){return impl->takeChange();}
|
||||
|
||||
@@ -21,7 +21,8 @@ class LanService
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
public:
|
||||
explicit LanService(const std::filesystem::path &, HWND inputWindow=nullptr, bool inputPaused=false);
|
||||
explicit LanService(const std::filesystem::path &, HWND inputWindow=nullptr, bool inputPaused=false,
|
||||
std::function<int()> additionalHeldKey={});
|
||||
~LanService();
|
||||
Bytes command(const Bytes &);
|
||||
void startClients();
|
||||
@@ -31,7 +32,10 @@ class LanService
|
||||
bool inputEnabled() const;
|
||||
void setInputPaused(bool);
|
||||
LanInputConnections inputConnections() const;
|
||||
bool tickInput(bool allowEnter = true);
|
||||
std::wstring inputBlockText() const;
|
||||
void forgetHeldInput();
|
||||
void requestHeldInputReset();
|
||||
bool tickInput(bool allowEnter = true, const std::function<void()> &resetHeldInput = {});
|
||||
bool keyboard(const KBDLLHOOKSTRUCT &, bool down);
|
||||
bool mouse(UINT, const MSLLHOOKSTRUCT &, bool allowEnter);
|
||||
bool takeInputChange();
|
||||
|
||||
@@ -13,6 +13,8 @@ struct InputFrame
|
||||
int32_t a{},b{},c{};
|
||||
bool operator==(const InputFrame &) const = default;
|
||||
};
|
||||
// A Return with no ownership token is ignored by older input routers.
|
||||
inline constexpr InputFrame ResetHeldInputRequest{InputType::Return,0,-2};
|
||||
// Collapse only contiguous, not-yet-delivered wheel events. A reversal replaces
|
||||
// stale queued motion; key/button boundaries must never be crossed.
|
||||
inline void enqueueInput(std::vector<InputFrame> &queue,const InputFrame &frame)
|
||||
|
||||
@@ -82,8 +82,11 @@ INPUT button(unsigned index,bool down)
|
||||
{MOUSEEVENTF_MIDDLEUP,MOUSEEVENTF_MIDDLEDOWN},{MOUSEEVENTF_XUP,MOUSEEVENTF_XDOWN},{MOUSEEVENTF_XUP,MOUSEEVENTF_XDOWN}};
|
||||
input.mi.dwFlags=flags[index][down];if(index>=3)input.mi.mouseData=index==3?XBUTTON1:XBUTTON2;return input;
|
||||
}
|
||||
bool windowsKeyDown(int key){return (GetAsyncKeyState(key)&0x8000)!=0;}
|
||||
UINT keyScan(int key){return MapVirtualKeyW(UINT(key),MAPVK_VK_TO_VSC_EX);}
|
||||
bool extendedKey(UINT scan){return (scan&0xff00)==0xe000;}
|
||||
}
|
||||
InputEnvironment windowsInputEnvironment()
|
||||
InputEnvironment windowsInputEnvironment(std::function<int()> additionalHeldKey)
|
||||
{
|
||||
auto overlay=std::make_shared<ControlOverlay>();
|
||||
return {
|
||||
@@ -91,7 +94,10 @@ InputEnvironment windowsInputEnvironment()
|
||||
[]{POINT p{};GetCursorPos(&p);return p;},
|
||||
[](const INPUT &i){INPUT input=i;return SendInput(1,&input,sizeof(input))==1;},
|
||||
ordinaryDesktop,
|
||||
[]{for(int key=1;key<256;++key)if(GetAsyncKeyState(key)&0x8000)return true;return false;},
|
||||
[additionalHeldKey=std::move(additionalHeldKey)]{
|
||||
if(additionalHeldKey)if(const int key=additionalHeldKey())return key;
|
||||
for(int key=1;key<256;++key)if(windowsKeyDown(key))return key;
|
||||
return 0;},
|
||||
[]{POINT p{};GetCursorPos(&p);MONITORINFO info{sizeof(info)};
|
||||
if(GetMonitorInfoW(MonitorFromPoint(p,MONITOR_DEFAULTTONEAREST),&info))p={(info.rcMonitor.left+info.rcMonitor.right)/2,(info.rcMonitor.top+info.rcMonitor.bottom)/2};
|
||||
return p;},
|
||||
@@ -99,6 +105,55 @@ InputEnvironment windowsInputEnvironment()
|
||||
monitorDpi
|
||||
};
|
||||
}
|
||||
std::wstring heldInputName(int key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case VK_LBUTTON:return L"Left mouse button";
|
||||
case VK_RBUTTON:return L"Right mouse button";
|
||||
case VK_MBUTTON:return L"Middle mouse button";
|
||||
case VK_XBUTTON1:return L"Mouse button 4";
|
||||
case VK_XBUTTON2:return L"Mouse button 5";
|
||||
case VK_MEDIA_PLAY_PAUSE:return L"Play/Pause";
|
||||
}
|
||||
if(key>0&&key<UnknownHeldInput)
|
||||
{
|
||||
if(auto name=Hotkey{0,UINT(key)}.format();!name.empty())return name;
|
||||
const auto scan=keyScan(key);
|
||||
wchar_t name[64]{};
|
||||
if(scan&&GetKeyNameTextW(LONG(((scan&0xff)<<16)|(extendedKey(scan)?1u<<24:0u)),name,int(std::size(name))))
|
||||
return name;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
std::vector<INPUT> heldInputReleases(const std::function<bool(int)> &isDown)
|
||||
{
|
||||
std::vector<INPUT> releases;
|
||||
for(int key=1;key<256;++key)
|
||||
{
|
||||
if(!isDown(key))continue;
|
||||
// Windows reports a generic modifier along with its left/right key.
|
||||
if((key==VK_SHIFT&&(isDown(VK_LSHIFT)||isDown(VK_RSHIFT)))||
|
||||
(key==VK_CONTROL&&(isDown(VK_LCONTROL)||isDown(VK_RCONTROL)))||
|
||||
(key==VK_MENU&&(isDown(VK_LMENU)||isDown(VK_RMENU))))continue;
|
||||
const auto mouse=std::find(MouseInputKeys.begin(),MouseInputKeys.end(),key);
|
||||
if(mouse!=MouseInputKeys.end())
|
||||
{
|
||||
auto release=button(unsigned(mouse-MouseInputKeys.begin()),false);
|
||||
release.mi.dwExtraInfo=inputMarker();
|
||||
releases.push_back(release);
|
||||
}
|
||||
else releases.push_back(keyboardInput(WORD(key),KEYEVENTF_KEYUP|
|
||||
(extendedKey(keyScan(key))||key==VK_MEDIA_PLAY_PAUSE?KEYEVENTF_EXTENDEDKEY:0)));
|
||||
}
|
||||
return releases;
|
||||
}
|
||||
bool resetWindowsHeldInput()
|
||||
{
|
||||
if(!ordinaryDesktop())return false;
|
||||
auto releases=heldInputReleases(windowsKeyDown);
|
||||
return releases.empty()||SendInput(UINT(releases.size()),releases.data(),sizeof(INPUT))==releases.size();
|
||||
}
|
||||
bool atEdge(POINT p,RECT r,int side)
|
||||
{return side==0?p.x<=r.left:side==1?p.x>=r.right-1:side==2?p.y<=r.top:p.y>=r.bottom-1;}
|
||||
int edgePosition(POINT p,RECT r,int side)
|
||||
@@ -140,9 +195,15 @@ bool InputRouter::move(POINT p,bool warp)
|
||||
return ok;
|
||||
}
|
||||
bool InputRouter::post(InputFrame f){return connected&&send(f);}
|
||||
bool InputRouter::held()const
|
||||
int InputRouter::heldKey()const
|
||||
{
|
||||
return std::any_of(physical.begin(),physical.end(),[](bool b){return b;})||env.held();
|
||||
const auto key=std::find(physical.begin(),physical.end(),true);
|
||||
return key!=physical.end()?int(key-physical.begin()):env.heldKey();
|
||||
}
|
||||
void InputRouter::noteHeldInput(int key)
|
||||
{
|
||||
if(!blockedKey_)log(L"LAN input: cursor handoff blocked by local input (VK "+std::to_wstring(key)+L")");
|
||||
blockedKey_=key;
|
||||
}
|
||||
void InputRouter::release()
|
||||
{
|
||||
@@ -159,7 +220,7 @@ void InputRouter::local(uint64_t now,int position)
|
||||
}
|
||||
bool InputRouter::handoff(int side,int position,uint64_t now)
|
||||
{
|
||||
if(!multi||mode_!=ControlMode::Sending||held()||side<0||side>3)return false;
|
||||
if(!multi||mode_!=ControlMode::Sending||heldKey()||side<0||side>3)return false;
|
||||
edge=side;transit=true;token=ownershipToken();
|
||||
requested=now;mode(ControlMode::Requesting);
|
||||
if(!post({InputType::Enter,token,edge,std::clamp(position,0,65535)})){cancel(now,"next computer unavailable");return false;}
|
||||
@@ -185,8 +246,10 @@ void InputRouter::tick(bool ready,uint64_t now)
|
||||
{returning=false;if(env.modeChanged)env.modeChanged(ControlMode::Local);}
|
||||
}
|
||||
connected=ready;
|
||||
const bool desktop=ready&&env.desktop();
|
||||
if(blockedKey_)blockedKey_=desktop?heldKey():0;
|
||||
if(!ready)cancel(now,"channel unavailable");
|
||||
else if(!env.desktop())cancel(now,"input desktop unavailable");
|
||||
else if(!desktop)cancel(now,"input desktop unavailable");
|
||||
else if(mode_==ControlMode::Requesting&&now-requested>1000)cancel(now,"handoff acknowledgement timed out");
|
||||
if(mode_==ControlMode::Sending&&awaitingWarp)
|
||||
{
|
||||
@@ -212,9 +275,14 @@ void InputRouter::receive(const InputFrame &f,uint64_t now)
|
||||
if(f.type==InputType::Enter)
|
||||
{
|
||||
const wchar_t *declined=nullptr;
|
||||
int blocked=0;
|
||||
if(!f.token||f.a<0||f.a>3||(!multi&&f.a!=(edge^1))||f.b<0||f.b>65535)
|
||||
declined=L"invalid edge or position";
|
||||
else if(held())declined=L"a local key or mouse button is held";
|
||||
else if((blocked=heldKey())!=0)
|
||||
{
|
||||
noteHeldInput(blocked);
|
||||
post({InputType::Return,f.token,32768,blocked});return;
|
||||
}
|
||||
else if(returning||mode_==ControlMode::Sending||mode_==ControlMode::Receiving||
|
||||
(mode_==ControlMode::Requesting&&preferLocal))
|
||||
declined=L"another handoff is active";
|
||||
@@ -225,7 +293,7 @@ void InputRouter::receive(const InputFrame &f,uint64_t now)
|
||||
}
|
||||
if(mode_==ControlMode::Requesting)cancel(now);
|
||||
if(multi)edge=f.a^1;
|
||||
crossEdge=-1;token=f.token;remainderX=remainderY=0;mode(ControlMode::Receiving);
|
||||
blockedKey_=0;crossEdge=-1;token=f.token;remainderX=remainderY=0;mode(ControlMode::Receiving);
|
||||
receivedPoint=edgePoint(env.bounds(),edge,f.b);
|
||||
awaitingEntry=true;entryStarted=now;
|
||||
if(!move(receivedPoint))cancel(now,"destination cursor injection failed");
|
||||
@@ -233,8 +301,13 @@ void InputRouter::receive(const InputFrame &f,uint64_t now)
|
||||
}
|
||||
if(f.type==InputType::Accept)
|
||||
{
|
||||
if(mode_!=ControlMode::Requesting||f.token!=token||held()||(!transit&&!atEdge(env.cursor(),env.bounds(),edge))){post({InputType::Return,f.token,32768});if(f.token==token)cancel(now);return;}
|
||||
transit=false;auto r=env.bounds();anchor=env.anchor?env.anchor():POINT{(r.left+r.right)/2,(r.top+r.bottom)/2};mode(ControlMode::Sending);
|
||||
const int blocked=mode_==ControlMode::Requesting&&f.token==token?heldKey():0;
|
||||
if(mode_!=ControlMode::Requesting||f.token!=token||blocked||(!transit&&!atEdge(env.cursor(),env.bounds(),edge)))
|
||||
{
|
||||
if(blocked)noteHeldInput(blocked);
|
||||
post({InputType::Return,f.token,32768});if(f.token==token)cancel(now);return;
|
||||
}
|
||||
blockedKey_=0;transit=false;auto r=env.bounds();anchor=env.anchor?env.anchor():POINT{(r.left+r.right)/2,(r.top+r.bottom)/2};mode(ControlMode::Sending);
|
||||
warpStarted=now;
|
||||
if(!move(anchor,true))cancel(now,"source cursor parking failed");
|
||||
return;
|
||||
@@ -358,8 +431,9 @@ bool InputRouter::mouse(UINT message,const MSLLHOOKSTRUCT &m,uint64_t now,bool a
|
||||
}
|
||||
if(index>=0&&outButtons[size_t(index)]){if(!down)outButtons[size_t(index)]=false;return true;}
|
||||
if(mode_==ControlMode::Local&&connected&&allowEnter&&message==WM_MOUSEMOVE&&now>=cooldown&&
|
||||
env.desktop()&&!held()&&atEdge(m.pt,env.bounds(),edge))
|
||||
env.desktop()&&atEdge(m.pt,env.bounds(),edge))
|
||||
{
|
||||
if(const int blocked=heldKey()){noteHeldInput(blocked);return false;}
|
||||
token=ownershipToken();
|
||||
returnPoint=m.pt;requested=now;mode(ControlMode::Requesting);
|
||||
if(!post({InputType::Enter,token,edge,edgePosition(m.pt,env.bounds(),edge)}))cancel(now);
|
||||
|
||||
@@ -4,18 +4,25 @@
|
||||
namespace ks::lan
|
||||
{
|
||||
enum class ControlMode { Local, Requesting, Sending, Receiving };
|
||||
// The Return frame's second field was unused. Older peers still return control.
|
||||
inline constexpr int UnknownHeldInput = 256;
|
||||
inline constexpr int HeldInputCleared = -1;
|
||||
struct InputEnvironment
|
||||
{
|
||||
std::function<RECT()> bounds;
|
||||
std::function<POINT()> cursor;
|
||||
std::function<bool(const INPUT &)> inject;
|
||||
std::function<bool()> desktop;
|
||||
std::function<bool()> held;
|
||||
std::function<int()> heldKey;
|
||||
std::function<POINT()> anchor;
|
||||
std::function<void(ControlMode)> modeChanged;
|
||||
std::function<int(POINT)> dpi;
|
||||
};
|
||||
InputEnvironment windowsInputEnvironment();
|
||||
inline constexpr std::array MouseInputKeys{VK_LBUTTON,VK_RBUTTON,VK_MBUTTON,VK_XBUTTON1,VK_XBUTTON2};
|
||||
InputEnvironment windowsInputEnvironment(std::function<int()> additionalHeldKey={});
|
||||
std::wstring heldInputName(int key);
|
||||
std::vector<INPUT> heldInputReleases(const std::function<bool(int)> &isDown);
|
||||
bool resetWindowsHeldInput();
|
||||
ULONG_PTR remoteInputMarker();
|
||||
ULONG_PTR cursorWarpMarker();
|
||||
bool atEdge(POINT,RECT,int edge);
|
||||
@@ -34,6 +41,7 @@ class InputRouter
|
||||
bool awaitingWarp{},awaitingEntry{};
|
||||
uint64_t warpStarted{},entryStarted{};
|
||||
bool returning{};POINT returnTarget{};uint64_t returnStarted{};
|
||||
int blockedKey_{};
|
||||
double remainderX{},remainderY{};
|
||||
std::array<bool,256> physical{},outKeys{},remoteKeys{};
|
||||
std::array<INPUT,256> releases{};
|
||||
@@ -42,7 +50,8 @@ class InputRouter
|
||||
bool emit(INPUT);
|
||||
bool move(POINT,bool warp=false);
|
||||
bool post(InputFrame);
|
||||
bool held() const;
|
||||
int heldKey() const;
|
||||
void noteHeldInput(int key);
|
||||
void release();
|
||||
void local(uint64_t now,int position=-1);
|
||||
public:
|
||||
@@ -50,7 +59,9 @@ class InputRouter
|
||||
~InputRouter();
|
||||
void selectEdge(int side,bool prefer){edge=side;preferLocal=prefer;}
|
||||
uint32_t sessionToken()const{return token;}
|
||||
bool canHandoff()const{return mode_==ControlMode::Sending&&!held();}
|
||||
bool canHandoff()const{return mode_==ControlMode::Sending&&!heldKey();}
|
||||
int blockedKey()const{return blockedKey_;}
|
||||
void forgetHeldKeys(){physical.fill(false);}
|
||||
bool handoff(int side,int position,uint64_t now);
|
||||
void returnAt(int side,int position,uint64_t now);
|
||||
ControlMode mode()const{return mode_;}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
#pragma once
|
||||
#include "lan_input.h"
|
||||
#include <map>
|
||||
#include <optional>
|
||||
namespace ks::lan
|
||||
{
|
||||
struct HandoffBlock
|
||||
{
|
||||
std::string peer; // Empty for this PC.
|
||||
int key{};
|
||||
};
|
||||
// The physical input source routes directly to the current destination. A
|
||||
// destination only reports edge crossings; it never relays injected key events.
|
||||
class InputMesh
|
||||
@@ -13,7 +19,17 @@ class InputMesh
|
||||
std::map<std::string,uint64_t> ready;
|
||||
std::function<bool(const std::string &,InputFrame)> send;
|
||||
uint64_t activeGeneration{},routeRevision{};
|
||||
struct Rejection {uint32_t token;uint64_t generation;int key;};
|
||||
std::map<std::string,Rejection> rejectedPeers;
|
||||
std::optional<std::pair<std::string,Rejection>> remoteBlock;
|
||||
InputRouter router;
|
||||
bool sendActive(InputFrame frame)
|
||||
{
|
||||
if(active.empty()||!ready.contains(active)||!send(active,frame))return false;
|
||||
if(frame.type==InputType::Return&&frame.b>0)
|
||||
rejectedPeers.insert_or_assign(active,Rejection{frame.token,ready.at(active),frame.b});
|
||||
return true;
|
||||
}
|
||||
std::string neighbor(const std::string &from,int side)const
|
||||
{
|
||||
POINT p{};if(from!=local){auto found=positions.find(from);if(found==positions.end())return {};p=found->second;}
|
||||
@@ -31,10 +47,22 @@ class InputMesh
|
||||
InputMesh(std::string id,InputEnvironment environment,std::map<std::string,POINT> layout,
|
||||
std::function<bool(const std::string &,InputFrame)> sender)
|
||||
:local(std::move(id)),env(std::move(environment)),positions(std::move(layout)),send(std::move(sender)),
|
||||
router(env,[this](InputFrame f){return !active.empty()&&ready.contains(active)&&send(active,f);},1,true,true){}
|
||||
router(env,[this](InputFrame f){return sendActive(f);},1,true,true){}
|
||||
ControlMode mode()const{return router.mode();}
|
||||
uint64_t revision()const{return router.revision()+routeRevision;}
|
||||
const std::string &peer()const{return active;}
|
||||
HandoffBlock handoffBlock()const
|
||||
{
|
||||
if(router.blockedKey())return {{},router.blockedKey()};
|
||||
if(remoteBlock)return {remoteBlock->first,remoteBlock->second.key};
|
||||
return {};
|
||||
}
|
||||
void forgetHeldKeys(){router.forgetHeldKeys();}
|
||||
void requestHeldInputReset(const std::function<bool(const std::string &)> &isPaired)
|
||||
{
|
||||
for(const auto &[peer,generation]:ready)
|
||||
if(isPaired(peer))send(peer,ResetHeldInputRequest);
|
||||
}
|
||||
void cancel(uint64_t now){router.cancel(now);}
|
||||
void tick(std::map<std::string,uint64_t> connections,uint64_t now)
|
||||
{
|
||||
@@ -44,10 +72,45 @@ class InputMesh
|
||||
if(connected&&activeGeneration!=ready.at(active)){router.cancel(now,"peer reconnected");activeGeneration=ready.at(active);}
|
||||
router.tick(connected,now);
|
||||
}
|
||||
const auto sameConnection=[this](const std::string &peer,const Rejection &rejection){
|
||||
auto connection=ready.find(peer);
|
||||
return connection!=ready.end()&&connection->second==rejection.generation;
|
||||
};
|
||||
if(remoteBlock&&!sameConnection(remoteBlock->first,remoteBlock->second))remoteBlock.reset();
|
||||
const int held=router.blockedKey();
|
||||
for(auto it=rejectedPeers.begin();it!=rejectedPeers.end();)
|
||||
{
|
||||
auto &[peer,rejection]=*it;
|
||||
if(!sameConnection(peer,rejection)){it=rejectedPeers.erase(it);continue;}
|
||||
if(held!=rejection.key&&send(peer,{InputType::Return,rejection.token,32768,held?held:HeldInputCleared}))
|
||||
rejection.key=held;
|
||||
if(!rejection.key)it=rejectedPeers.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
}
|
||||
void receive(const std::string &peer,const InputFrame &f,uint64_t now,bool allowEnter=true)
|
||||
void receive(const std::string &peer,const InputFrame &f,uint64_t now,bool allowEnter=true,
|
||||
const std::function<void()> &resetHeldInput={})
|
||||
{
|
||||
if(!ready.contains(peer)||!positions.contains(peer))return;
|
||||
if(!ready.contains(peer))return;
|
||||
if(f==ResetHeldInputRequest)
|
||||
{
|
||||
if(allowEnter&&resetHeldInput)resetHeldInput();
|
||||
return;
|
||||
}
|
||||
if(!positions.contains(peer))return;
|
||||
if(f.type==InputType::Return)
|
||||
{
|
||||
const bool held=f.b>0&&f.b<=UnknownHeldInput;
|
||||
if(remoteBlock&&remoteBlock->first==peer&&remoteBlock->second.token==f.token)
|
||||
{
|
||||
// These updates belong to a completed request, never the current owner.
|
||||
if(f.b==HeldInputCleared)remoteBlock.reset();
|
||||
else if(held)remoteBlock->second.key=f.b;
|
||||
return;
|
||||
}
|
||||
if(held&&active==peer&&router.mode()==ControlMode::Requesting&&router.sessionToken()==f.token)
|
||||
remoteBlock=std::pair{peer,Rejection{f.token,ready.at(peer),f.b}};
|
||||
}
|
||||
if(f.type==InputType::Enter){
|
||||
if(!allowEnter||f.a<0||f.a>3||(router.mode()!=ControlMode::Local&&active!=peer)){
|
||||
if(!allowEnter)log(L"LAN input: declined cursor handoff during a local text operation or shortcut capture");
|
||||
@@ -66,6 +129,7 @@ class InputMesh
|
||||
router.handoff(f.a,f.b,now);return;
|
||||
}
|
||||
router.receive(f,now);
|
||||
if(router.mode()==ControlMode::Sending||router.mode()==ControlMode::Receiving)remoteBlock.reset();
|
||||
}
|
||||
bool keyboard(const KBDLLHOOKSTRUCT &key,bool down,uint64_t now){return router.keyboard(key,down,now);}
|
||||
bool mouse(UINT message,const MSLLHOOKSTRUCT &mouse,uint64_t now,bool allowEnter=true)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
namespace ks
|
||||
{
|
||||
enum class NavigationIcon
|
||||
{
|
||||
#define NAVIGATION_ICON(name, id, file) name = id,
|
||||
#include "../resources/navigation_icons.inc"
|
||||
#undef NAVIGATION_ICON
|
||||
};
|
||||
|
||||
inline HBITMAP iconBitmap(HICON icon, int width, int height, void **data = nullptr)
|
||||
{
|
||||
if (!icon || width < 1 || height < 1) return nullptr;
|
||||
BITMAPINFO info{};
|
||||
info.bmiHeader = {sizeof(BITMAPINFOHEADER), width, -height, 1, 32, BI_RGB};
|
||||
void *bits{};
|
||||
const HBITMAP bitmap = CreateDIBSection(nullptr, &info, DIB_RGB_COLORS, &bits, nullptr, 0);
|
||||
if (!bitmap) return nullptr;
|
||||
BOOL drawn = FALSE;
|
||||
if (const HDC dc = CreateCompatibleDC(nullptr))
|
||||
{
|
||||
const auto previous = SelectObject(dc, bitmap);
|
||||
std::fill_n(static_cast<std::uint32_t *>(bits), static_cast<std::size_t>(width) * height, 0);
|
||||
drawn = DrawIconEx(dc, 0, 0, icon, width, height, 0, nullptr, DI_NORMAL);
|
||||
GdiFlush();
|
||||
SelectObject(dc, previous);
|
||||
DeleteDC(dc);
|
||||
}
|
||||
if (drawn)
|
||||
{
|
||||
if (data) *data = bits;
|
||||
return bitmap;
|
||||
}
|
||||
DeleteObject(bitmap);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline HBITMAP navigationIconBitmap(HINSTANCE instance, NavigationIcon icon, int size, COLORREF color)
|
||||
{
|
||||
const auto source = static_cast<HICON>(LoadImageW(instance, MAKEINTRESOURCEW(static_cast<int>(icon)),
|
||||
IMAGE_ICON, size, size, 0));
|
||||
void *bits{};
|
||||
const auto bitmap = iconBitmap(source, size, size, &bits);
|
||||
if (source) DestroyIcon(source);
|
||||
if (!bitmap) return nullptr;
|
||||
auto *pixels = static_cast<std::uint32_t *>(bits);
|
||||
for (int i = 0; i < size * size; ++i)
|
||||
{
|
||||
const auto alpha = pixels[i] >> 24;
|
||||
const auto channel = [alpha](unsigned value) { return (value * alpha + 127) / 255; };
|
||||
pixels[i] = alpha << 24 | channel(GetRValue(color)) << 16 |
|
||||
channel(GetGValue(color)) << 8 | channel(GetBValue(color));
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
inline constexpr COLORREF NavigationIconColor = RGB(69, 92, 126);
|
||||
inline constexpr COLORREF NavigationIconAccent = RGB(84, 66, 216);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "platform.h"
|
||||
#include "windows_command_line.h"
|
||||
#include "../vendor/json.hpp"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <shldisp.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <wincrypt.h>
|
||||
#include <winhttp.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
namespace ks
|
||||
@@ -348,9 +350,10 @@ std::wstring mouseApplicationName(HWND window)
|
||||
}, reinterpret_cast<LPARAM>(&hosted));
|
||||
return hosted.empty() ? name : hosted;
|
||||
}
|
||||
bool launchThroughExplorer(const std::wstring &path)
|
||||
namespace
|
||||
{
|
||||
bool shellOpenThroughExplorer(const std::wstring &target, const std::wstring &arguments, const std::wstring &directory)
|
||||
{
|
||||
const auto directory = std::filesystem::path(path).parent_path().wstring();
|
||||
HANDLE token{};
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) return false;
|
||||
TOKEN_ELEVATION elevation{};
|
||||
@@ -362,7 +365,8 @@ bool launchThroughExplorer(const std::wstring &path)
|
||||
{
|
||||
SHELLEXECUTEINFOW launch{sizeof(launch)};
|
||||
launch.fMask = SEE_MASK_FLAG_NO_UI;
|
||||
launch.lpFile = path.c_str();
|
||||
launch.lpFile = target.c_str();
|
||||
launch.lpParameters = arguments.empty() ? nullptr : arguments.c_str();
|
||||
launch.lpDirectory = directory.empty() ? nullptr : directory.c_str();
|
||||
launch.nShow = SW_SHOWNORMAL;
|
||||
return ShellExecuteExW(&launch) != FALSE;
|
||||
@@ -410,17 +414,126 @@ bool launchThroughExplorer(const std::wstring &path)
|
||||
hr = application->QueryInterface(IID_IShellDispatch2, reinterpret_cast<void **>(&shellRaw));
|
||||
std::unique_ptr<IShellDispatch2, decltype(release)> shell(shellRaw, release);
|
||||
if (FAILED(hr) || !shell) return false;
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> executable(SysAllocString(path.c_str()), SysFreeString);
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> executable(SysAllocString(target.c_str()), SysFreeString);
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> workingDirectory(SysAllocString(directory.c_str()), SysFreeString);
|
||||
if (!executable || !workingDirectory) return false;
|
||||
VARIANT location{}, shown{};
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> parameters(SysAllocString(arguments.c_str()), SysFreeString);
|
||||
if (!executable || !workingDirectory || !parameters) return false;
|
||||
VARIANT location{}, shown{}, args{};
|
||||
location.vt = VT_BSTR;
|
||||
location.bstrVal = workingDirectory.get();
|
||||
shown.vt = VT_I4;
|
||||
shown.lVal = SW_SHOWNORMAL;
|
||||
hr = shell->ShellExecute(executable.get(), empty, location, empty, shown);
|
||||
args.vt = VT_BSTR;
|
||||
args.bstrVal = parameters.get();
|
||||
hr = shell->ShellExecute(executable.get(), args, location, empty, shown);
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
std::filesystem::path shortcutKnownFolder(REFKNOWNFOLDERID folder)
|
||||
{
|
||||
PWSTR raw{};
|
||||
if (FAILED(SHGetKnownFolderPath(folder, 0, nullptr, &raw))) return {};
|
||||
std::unique_ptr<wchar_t, decltype(&CoTaskMemFree)> path(raw, CoTaskMemFree);
|
||||
return std::filesystem::path(path.get());
|
||||
}
|
||||
|
||||
std::filesystem::path chromeUserData()
|
||||
{
|
||||
const auto local = shortcutKnownFolder(FOLDERID_LocalAppData);
|
||||
return local.empty() ? local : local / L"Google/Chrome/User Data";
|
||||
}
|
||||
|
||||
std::filesystem::path chromeExecutable()
|
||||
{
|
||||
constexpr wchar_t key[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe";
|
||||
std::error_code ec;
|
||||
for (const auto hive : {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE})
|
||||
{
|
||||
wchar_t path[32768]{};
|
||||
DWORD bytes = sizeof(path);
|
||||
if (RegGetValueW(hive, key, nullptr, RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ, nullptr, path, &bytes) == ERROR_SUCCESS)
|
||||
{
|
||||
const std::filesystem::path candidate(path);
|
||||
if (candidate.is_absolute() && lower(candidate.filename().wstring()) == L"chrome.exe" &&
|
||||
std::filesystem::is_regular_file(candidate, ec)) return candidate;
|
||||
}
|
||||
}
|
||||
for (const auto *folder : {&FOLDERID_LocalAppData, &FOLDERID_ProgramFiles, &FOLDERID_ProgramFilesX86})
|
||||
{
|
||||
const auto base = shortcutKnownFolder(*folder);
|
||||
if (base.empty()) continue;
|
||||
const auto candidate = (base / L"Google/Chrome/Application/chrome.exe").make_preferred();
|
||||
if (std::filesystem::is_regular_file(candidate, ec)) return candidate;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool launchThroughExplorer(const std::wstring &path)
|
||||
{
|
||||
return shellOpenThroughExplorer(path, {}, std::filesystem::path(path).parent_path().wstring());
|
||||
}
|
||||
|
||||
bool validShortcutUrl(const std::wstring &url)
|
||||
{
|
||||
if (url.empty() || url.size() > 16384 || std::any_of(url.begin(), url.end(), [](wchar_t ch) {
|
||||
return ch <= L' ' || ch == L'\x7f' || ch == L'\\' || ch == L'"';
|
||||
})) return false;
|
||||
URL_COMPONENTSW parts{};
|
||||
parts.dwStructSize = sizeof(parts);
|
||||
parts.dwHostNameLength = static_cast<DWORD>(-1);
|
||||
return WinHttpCrackUrl(url.c_str(), static_cast<DWORD>(url.size()), 0, &parts) &&
|
||||
(parts.nScheme == INTERNET_SCHEME_HTTP || parts.nScheme == INTERNET_SCHEME_HTTPS) && parts.dwHostNameLength;
|
||||
}
|
||||
|
||||
bool validChromeProfileName(std::wstring_view name)
|
||||
{
|
||||
return !name.empty() && name.size() <= 255 && name.back() != L'.' && name.back() != L' ' &&
|
||||
name.find_first_of(L"<>:\"/\\|?*") == name.npos && std::none_of(name.begin(), name.end(), [](wchar_t ch) {
|
||||
return ch < L' ';
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::wstring, std::wstring>> chromeShortcutProfiles()
|
||||
{
|
||||
std::vector<std::pair<std::wstring, std::wstring>> profiles;
|
||||
const auto root = chromeUserData();
|
||||
if (root.empty()) return profiles;
|
||||
try
|
||||
{
|
||||
const auto state = nlohmann::json::parse(readFile(root / L"Local State", 16 * 1024 * 1024));
|
||||
const auto &cache = state.at("profile").at("info_cache");
|
||||
if (!cache.is_object()) return profiles;
|
||||
for (const auto &[id, entry] : cache.items())
|
||||
{
|
||||
const auto directory = wide(id);
|
||||
std::error_code ec;
|
||||
if (!validChromeProfileName(directory) || !entry.is_object() ||
|
||||
!std::filesystem::is_directory(root / directory, ec)) continue;
|
||||
auto display = entry.find("name");
|
||||
const auto name = display != entry.end() && display->is_string() ? wide(display->get<std::string>()) : directory;
|
||||
profiles.emplace_back(directory, name.empty() ? directory : name);
|
||||
}
|
||||
}
|
||||
catch (const std::exception &) {} // Chrome may be uninstalled or may be rewriting Local State.
|
||||
return profiles;
|
||||
}
|
||||
|
||||
bool openShortcutUrl(const CustomShortcut &rule)
|
||||
{
|
||||
if (rule.browser == ShortcutBrowser::Default) return shellOpenThroughExplorer(rule.url, {}, {});
|
||||
const auto path = rule.browser == ShortcutBrowser::Chrome ? chromeExecutable() : std::filesystem::path(rule.executable);
|
||||
if (path.empty()) return false;
|
||||
auto arguments = quoteWindowsArgument(rule.url);
|
||||
if (rule.browser == ShortcutBrowser::Chrome && !rule.chromeProfile.empty())
|
||||
{
|
||||
const auto root = chromeUserData();
|
||||
std::error_code ec;
|
||||
if (root.empty() || !std::filesystem::is_directory(root / rule.chromeProfile, ec)) return false;
|
||||
arguments = quoteWindowsArgument(L"--profile-directory=" + rule.chromeProfile) + L" " + arguments;
|
||||
}
|
||||
return shellOpenThroughExplorer(path.wstring(), arguments, path.parent_path().wstring());
|
||||
}
|
||||
bool clipboardHasImage()
|
||||
{
|
||||
return IsClipboardFormatAvailable(CF_DIB) || IsClipboardFormatAvailable(CF_DIBV5) ||
|
||||
|
||||
@@ -54,6 +54,10 @@ std::wstring shortcutTextControlClass(HWND);
|
||||
HWND findShortcutTextControl(HWND, std::wstring_view controlClass, int controlId);
|
||||
std::wstring mouseApplicationName(HWND);
|
||||
bool launchThroughExplorer(const std::wstring &);
|
||||
bool validShortcutUrl(const std::wstring &);
|
||||
bool validChromeProfileName(std::wstring_view);
|
||||
std::vector<std::pair<std::wstring, std::wstring>> chromeShortcutProfiles();
|
||||
bool openShortcutUrl(const CustomShortcut &);
|
||||
enum class ClipboardRead { All, Selection, WithoutImages };
|
||||
bool clipboardHasImage();
|
||||
Clip readClipboard(HWND, size_t limit = 32 * 1024 * 1024,
|
||||
|
||||
@@ -216,10 +216,21 @@ void validateSettings(const Settings &s)
|
||||
const auto key = Hotkey::parse(rule.shortcut);
|
||||
if (!key || !key->key)
|
||||
throw std::runtime_error("Enter a key combination for the custom shortcut.");
|
||||
const std::filesystem::path path(rule.executable);
|
||||
if (rule.executable.size() > 32700 || rule.executable.find_first_of(L"\r\n\"") != std::wstring::npos ||
|
||||
rule.executable.find(L'\0') != std::wstring::npos || !path.is_absolute() || lower(path.extension().wstring()) != L".exe")
|
||||
throw std::runtime_error("Choose a program executable (.exe) for the custom shortcut.");
|
||||
if (rule.action != CustomShortcutAction::OpenUrl || rule.browser == ShortcutBrowser::Other)
|
||||
{
|
||||
const std::filesystem::path path(rule.executable);
|
||||
if (rule.executable.size() > 32700 || rule.executable.find_first_of(L"\r\n\"") != std::wstring::npos ||
|
||||
rule.executable.find(L'\0') != std::wstring::npos || !path.is_absolute() || lower(path.extension().wstring()) != L".exe")
|
||||
throw std::runtime_error("Choose a program executable (.exe) for the custom shortcut.");
|
||||
}
|
||||
if (rule.action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
if (!validShortcutUrl(rule.url)) throw std::runtime_error("Enter a valid HTTP or HTTPS URL.");
|
||||
if (rule.browser != ShortcutBrowser::Default && rule.browser != ShortcutBrowser::Chrome && rule.browser != ShortcutBrowser::Other)
|
||||
throw std::runtime_error("Choose a browser for the URL shortcut.");
|
||||
if (rule.browser == ShortcutBrowser::Chrome && !rule.chromeProfile.empty() && !validChromeProfileName(rule.chromeProfile))
|
||||
throw std::runtime_error("Choose a valid Chrome profile.");
|
||||
}
|
||||
if (rule.action == CustomShortcutAction::SendText &&
|
||||
(rule.controlClass.empty() || rule.controlClass.size() > 255 || rule.text.empty() ||
|
||||
rule.text.size() > 32768 || rule.text.find(L'\0') != std::wstring::npos))
|
||||
@@ -399,7 +410,6 @@ Settings decodeSettings(const Bytes &bytes, const std::vector<Layout> &layouts)
|
||||
for (const auto &rule : rules)
|
||||
{
|
||||
const auto action = rule.value("action", "launchApp");
|
||||
if (action != "launchApp" && action != "sendText") throw std::runtime_error("Unknown custom shortcut action.");
|
||||
CustomShortcut shortcut{str(rule, "name", L""), str(rule, "shortcut", L""),
|
||||
str(rule, "executable", L""), rule.value("enabled", true)};
|
||||
if (action == "sendText")
|
||||
@@ -409,7 +419,21 @@ Settings decodeSettings(const Bytes &bytes, const std::vector<Layout> &layouts)
|
||||
shortcut.text = str(rule, "text", L"");
|
||||
shortcut.controlId = rule.value("controlId", 0);
|
||||
}
|
||||
else shortcut.newInstance = rule.value("newInstance", false);
|
||||
else if (action == "openUrl")
|
||||
{
|
||||
shortcut.action = CustomShortcutAction::OpenUrl;
|
||||
shortcut.url = str(rule, "url", L"");
|
||||
const auto browser = rule.value("browser", "default");
|
||||
if (browser == "chrome")
|
||||
{
|
||||
shortcut.browser = ShortcutBrowser::Chrome;
|
||||
shortcut.chromeProfile = str(rule, "chromeProfile", L"");
|
||||
}
|
||||
else if (browser == "other") shortcut.browser = ShortcutBrowser::Other;
|
||||
else if (browser != "default") throw std::runtime_error("Unknown shortcut browser.");
|
||||
}
|
||||
else if (action == "launchApp") shortcut.newInstance = rule.value("newInstance", false);
|
||||
else throw std::runtime_error("Unknown custom shortcut action.");
|
||||
s.customShortcuts.push_back(std::move(shortcut));
|
||||
}
|
||||
}
|
||||
@@ -588,6 +612,15 @@ Bytes encodeSettings(const Settings &s)
|
||||
item["controlId"] = rule.controlId;
|
||||
item["text"] = utf8(rule.text);
|
||||
}
|
||||
else if (rule.action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
item["action"] = "openUrl";
|
||||
item["url"] = utf8(rule.url);
|
||||
item["browser"] = rule.browser == ShortcutBrowser::Chrome ? "chrome" :
|
||||
rule.browser == ShortcutBrowser::Other ? "other" : "default";
|
||||
if (rule.browser == ShortcutBrowser::Chrome && !rule.chromeProfile.empty())
|
||||
item["chromeProfile"] = utf8(rule.chromeProfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
item["action"] = "launchApp";
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "diagnostics.h"
|
||||
#include "google_drive.h"
|
||||
#include "update.h"
|
||||
#include "navigation_icons.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
@@ -481,6 +482,62 @@ HWND makeWindow(App &app, const wchar_t *cls, const wchar_t *title, WNDPROC proc
|
||||
SetPropW(w, L"Dpi", (HANDLE)(UINT_PTR)GetDpiForWindow(w));
|
||||
return w;
|
||||
}
|
||||
#ifndef KS_RESIDENT_APP
|
||||
constexpr int ModalFooterHeight = 50;
|
||||
|
||||
LRESULT CALLBACK settingsModalPaletteProc(HWND w, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR id, DWORD_PTR data)
|
||||
{
|
||||
auto *palette = reinterpret_cast<WindowPalette *>(data);
|
||||
if (msg == WM_ERASEBKGND)
|
||||
{
|
||||
const auto dc = reinterpret_cast<HDC>(wp);
|
||||
RECT area{};
|
||||
GetClientRect(w, &area);
|
||||
FillRect(dc, &area, GetSysColorBrush(COLOR_WINDOW));
|
||||
area.top = std::max(0L, area.bottom - scale(w, ModalFooterHeight));
|
||||
FillRect(dc, &area, palette->brush());
|
||||
fillSurface(dc, {area.left, area.top, area.right, area.top + 1}, palette->edge());
|
||||
return 1;
|
||||
}
|
||||
if (msg == WM_CTLCOLORSTATIC)
|
||||
{
|
||||
const auto dc = reinterpret_cast<HDC>(wp);
|
||||
SetBkColor(dc, GetSysColor(COLOR_WINDOW));
|
||||
return reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_WINDOW));
|
||||
}
|
||||
if (msg == WM_SYSCOLORCHANGE || msg == WM_THEMECHANGED || msg == WM_SETTINGCHANGE || msg == WM_DWMCOLORIZATIONCOLORCHANGED)
|
||||
{
|
||||
palette->refresh();
|
||||
RedrawWindow(w, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
|
||||
}
|
||||
if (msg == WM_NCDESTROY)
|
||||
{
|
||||
RemoveWindowSubclass(w, settingsModalPaletteProc, id);
|
||||
delete palette;
|
||||
}
|
||||
return DefSubclassProc(w, msg, wp, lp);
|
||||
}
|
||||
|
||||
HWND makeSettingsModal(App &app, HWND owner, const wchar_t *cls, const wchar_t *title, WNDPROC proc, int width, int height)
|
||||
{
|
||||
auto palette = std::make_unique<WindowPalette>();
|
||||
palette->refresh();
|
||||
const auto w = makeWindow(app, cls, title, proc, width, height, 0, false, owner);
|
||||
windowLayoutState(w)->fixedClient = true;
|
||||
if (SetWindowSubclass(w, settingsModalPaletteProc, 1, reinterpret_cast<DWORD_PTR>(palette.get()))) palette.release();
|
||||
return w;
|
||||
}
|
||||
|
||||
void settingsModalActions(HWND w, int width, int height, const wchar_t *accept, int extraId = 0, const wchar_t *extra = nullptr)
|
||||
{
|
||||
constexpr int margin = 22, acceptWidth = 120, cancelWidth = 90, gap = 12;
|
||||
const int y = height - (ModalFooterHeight + 28) / 2;
|
||||
const int x = width - margin - acceptWidth;
|
||||
if (extra) button(w, extra, extraId, margin, y, cancelWidth);
|
||||
button(w, L"Cancel", IDCANCEL, x - gap - cancelWidth, y, cancelWidth);
|
||||
control(w, L"BUTTON", accept, WS_TABSTOP | WS_GROUP | BS_DEFPUSHBUTTON, IDOK, x, y, acceptWidth, 28);
|
||||
}
|
||||
#endif
|
||||
void resizeForDpi(HWND w, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
// Creation may send WM_DPICHANGED before controls and the original font exist.
|
||||
@@ -1062,8 +1119,12 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
auto old = selected(w, v);
|
||||
if (old.empty()) old = v->rememberedSelection;
|
||||
int top=(int)SendDlgItemMessageW(w,102,LB_GETTOPINDEX,0,0);
|
||||
auto topId=top>=0 && top<(int)v->items.size()?v->items[top].id:L"";
|
||||
if (topId.empty()) topId = v->rememberedTop;
|
||||
// Follow new entries at the top. Anchor the viewport only while browsing older rows.
|
||||
std::wstring topId;
|
||||
if (top > 0 && top < (int)v->items.size())
|
||||
topId = v->items[top].id;
|
||||
else if (v->items.empty())
|
||||
topId = v->rememberedTop;
|
||||
if (v->selectFirstOnResults)
|
||||
{
|
||||
old.clear();
|
||||
@@ -1225,7 +1286,7 @@ constexpr int OcrUseTesseract = 501, OcrExecutable = 502, OcrLanguages = 503, Oc
|
||||
OcrCheck = 505, OcrStatus = 506, OcrDownload = 507;
|
||||
constexpr int DriveAutomatic = 625;
|
||||
constexpr UINT CollapseSettingsGroupMessage = WM_APP + 188;
|
||||
constexpr int SettingsSidebarWidth = 214, SettingsHeaderHeight = 82, SettingsFooterHeight = 76;
|
||||
constexpr int SettingsSidebarWidth = 256, SettingsHeaderHeight = 82, SettingsFooterHeight = 76;
|
||||
constexpr int SettingsNavigationIndent = 16;
|
||||
constexpr int SettingsSplitter = 270, SettingsSplitterWidth = 8;
|
||||
constexpr int SettingsSidebarMin = 164, SettingsSidebarMax = 420, SettingsPaneMin = 320;
|
||||
@@ -1235,30 +1296,31 @@ constexpr struct SettingsSection
|
||||
{
|
||||
const char *key;
|
||||
const wchar_t *name, *description;
|
||||
NavigationIcon icon;
|
||||
int parent = -1;
|
||||
} settingsSections[] = {
|
||||
{"general", L"General", L"Configure text conversion and how KSwitcher runs on Windows."},
|
||||
{"languages", L"Languages", L"Order layouts from top to bottom and override the cycle for individual chats or apps."},
|
||||
{"shortcuts", L"Shortcuts", L"Click a shortcut field and press the desired keys. Backspace or Delete clears it."},
|
||||
{"clipboard", L"Clipboard", L"Configure clipboard history, storage limits and excluded applications."},
|
||||
{"snippets", L"Snippets", L"Create text expansions and choose which applications can use them."},
|
||||
{"mouse", L"Mouse", L"Manage profiles, assign actions and test your mouse buttons."},
|
||||
{"sync", L"Sync", L"Choose a provider to back up or synchronize your settings."},
|
||||
{"computers", L"Computers", L"Share mouse and keyboard with paired computers."},
|
||||
{"diagnostics", L"Diagnostics", L"Manage diagnostic logging and view recent operations."},
|
||||
{"mcp", L"MCP", L"Connect Codex to KSwitcher to read diagnostic logs."},
|
||||
{"manage-computers", L"Manage computers", L"Pair computers, arrange their screens and manage input sharing.", ComputersPage},
|
||||
{"correction", L"Correction options", L"Choose a subsection to configure automatic correction.", GeneralPage},
|
||||
{"offline-dictionaries", L"Offline dictionaries", L"Choose dictionary languages and set limits for automatic correction.", CorrectionPage},
|
||||
{"correction-exceptions", L"Exceptions", L"Exclude applications and words from automatic correction.", CorrectionPage},
|
||||
{"personal-dictionaries", L"Personal dictionaries", L"Separate words with commas or new lines. Internal hyphens are allowed.", CorrectionPage},
|
||||
{"word-boundaries", L"Word boundaries", L"Choose which punctuation KSwitcher keeps before and after a corrected word.", CorrectionPage},
|
||||
{"custom-replacements", L"Custom replacements", L"Define your own corrections, which take priority over dictionary suggestions.", CorrectionPage},
|
||||
{"openbao", L"OpenBao", L"Connect to OpenBao and synchronize your saved settings.", SyncPage},
|
||||
{"google-drive", L"Google Drive", L"Synchronize settings across PCs or manage manual backups.", SyncPage},
|
||||
{"ocr", L"Image text recognition", L"Choose Windows OCR or Tesseract. Recognition runs on this computer.", ClipboardPage},
|
||||
{"chat-languages", L"Languages for a chat", L"Choose which keyboard layouts to cycle through in a chat.", LanguagesPage},
|
||||
{"custom-shortcuts", L"Custom shortcuts", L"Assign global keyboard shortcuts to actions in other apps.", ShortcutsPage},
|
||||
{"general", L"General", L"Configure text conversion and how KSwitcher runs on Windows.", NavigationIcon::Gear},
|
||||
{"languages", L"Languages", L"Order layouts from top to bottom and override the cycle for individual chats or apps.", NavigationIcon::Globe},
|
||||
{"shortcuts", L"Shortcuts", L"Click a shortcut field and press the desired keys. Backspace or Delete clears it.", NavigationIcon::Keyboard},
|
||||
{"clipboard", L"Clipboard", L"Configure clipboard history, storage limits and excluded applications.", NavigationIcon::Clip},
|
||||
{"snippets", L"Snippets", L"Create text expansions and choose which applications can use them.", NavigationIcon::Snippet},
|
||||
{"mouse", L"Mouse", L"Manage profiles, assign actions and test your mouse buttons.", NavigationIcon::Mouse},
|
||||
{"sync", L"Sync", L"Choose a provider to back up or synchronize your settings.", NavigationIcon::Sync},
|
||||
{"computers", L"Computers", L"Share mouse and keyboard with paired computers.", NavigationIcon::Computers},
|
||||
{"diagnostics", L"Diagnostics", L"Manage diagnostic logging and view recent operations.", NavigationIcon::Pulse},
|
||||
{"mcp", L"MCP", L"Connect Codex to KSwitcher to read diagnostic logs.", NavigationIcon::Connect},
|
||||
{"manage-computers", L"Manage computers", L"Pair computers, arrange their screens and manage input sharing.", NavigationIcon::Manage, ComputersPage},
|
||||
{"correction", L"Correction options", L"Choose a subsection to configure automatic correction.", NavigationIcon::Check, GeneralPage},
|
||||
{"offline-dictionaries", L"Offline dictionaries", L"Choose dictionary languages and set limits for automatic correction.", NavigationIcon::Book, CorrectionPage},
|
||||
{"correction-exceptions", L"Exceptions", L"Exclude applications and words from automatic correction.", NavigationIcon::Ban, CorrectionPage},
|
||||
{"personal-dictionaries", L"Personal dictionaries", L"Separate words with commas or new lines. Internal hyphens are allowed.", NavigationIcon::Personal, CorrectionPage},
|
||||
{"word-boundaries", L"Word boundaries", L"Choose which punctuation KSwitcher keeps before and after a corrected word.", NavigationIcon::Bounds, CorrectionPage},
|
||||
{"custom-replacements", L"Custom replacements", L"Define your own corrections, which take priority over dictionary suggestions.", NavigationIcon::Replace, CorrectionPage},
|
||||
{"openbao", L"OpenBao", L"Connect to OpenBao and synchronize your saved settings.", NavigationIcon::Vault, SyncPage},
|
||||
{"google-drive", L"Google Drive", L"Synchronize settings across PCs or manage manual backups.", NavigationIcon::Drive, SyncPage},
|
||||
{"ocr", L"Image text recognition", L"Choose Windows OCR or Tesseract. Recognition runs on this computer.", NavigationIcon::Scan, ClipboardPage},
|
||||
{"chat-languages", L"Languages for a chat", L"Choose which keyboard layouts to cycle through in a chat.", NavigationIcon::Chat, LanguagesPage},
|
||||
{"custom-shortcuts", L"Custom shortcuts", L"Assign global keyboard shortcuts to actions in other apps.", NavigationIcon::Command, ShortcutsPage},
|
||||
};
|
||||
constexpr wchar_t SettingsWindowFile[] = L"configurator-window.json";
|
||||
struct SettingsWindowState
|
||||
@@ -1345,6 +1407,7 @@ struct SettingsView
|
||||
std::optional<int> splitterDragOffset;
|
||||
bool splitterHovered{};
|
||||
std::array<HTREEITEM, std::size(settingsSections)> navigationItems{};
|
||||
HIMAGELIST navigationIcons{};
|
||||
struct SearchEntry { int page; HWND caption, target; std::wstring title, aliases; bool matched{}; };
|
||||
std::vector<SearchEntry> searchEntries;
|
||||
std::optional<size_t> activeSearchEntry;
|
||||
@@ -2010,11 +2073,40 @@ void selectSettingsPage(SettingsView &v, int selected)
|
||||
for (size_t i = page.first; i < page.end; ++i) ShowWindow(layout.controls[i].first, SW_SHOWNA);
|
||||
InvalidateRect(v.viewport, nullptr, TRUE);
|
||||
}
|
||||
void refreshSettingsNavigationIcons(SettingsView &v, UINT dpi)
|
||||
{
|
||||
constexpr int count = static_cast<int>(std::size(settingsSections));
|
||||
const int size = MulDiv(16, dpi, USER_DEFAULT_SCREEN_DPI);
|
||||
const auto images = ImageList_Create(size, size, ILC_COLOR32, 2 * (count + 1), 0);
|
||||
if (!images) return;
|
||||
for (bool selected : {false, true})
|
||||
{
|
||||
const COLORREF color = v.palette.highContrast ?
|
||||
GetSysColor(selected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT) :
|
||||
selected ? NavigationIconAccent : NavigationIconColor;
|
||||
for (int page = 0; page <= count; ++page)
|
||||
{
|
||||
const auto icon = page == count ? NavigationIcon::Search : settingsSections[page].icon;
|
||||
const auto bitmap = navigationIconBitmap(v.app->instance, icon, size, color);
|
||||
const int index = bitmap ? ImageList_Add(images, bitmap, nullptr) : -1;
|
||||
if (bitmap) DeleteObject(bitmap);
|
||||
if (index < 0)
|
||||
{
|
||||
ImageList_Destroy(images);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
TreeView_SetImageList(v.navigation, images, TVSIL_NORMAL);
|
||||
if (v.navigationIcons) ImageList_Destroy(v.navigationIcons);
|
||||
v.navigationIcons = images;
|
||||
}
|
||||
void refreshSettingsColors(HWND w, SettingsView &v, std::optional<DWORD> colorization = std::nullopt)
|
||||
{
|
||||
v.palette.refresh(colorization);
|
||||
TreeView_SetBkColor(v.navigation, v.palette.color());
|
||||
TreeView_SetTextColor(v.navigation, GetSysColor(COLOR_WINDOWTEXT));
|
||||
refreshSettingsNavigationIcons(v, GetDpiForWindow(w));
|
||||
RedrawWindow(w, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
|
||||
}
|
||||
void paintSettings(HWND w, const SettingsView &v)
|
||||
@@ -2044,7 +2136,11 @@ HTREEITEM addSettingsNode(HWND tree, HTREEITEM parent, const wchar_t *title, LPA
|
||||
TVINSERTSTRUCTW node{};
|
||||
node.hParent = parent;
|
||||
node.hInsertAfter = TVI_LAST;
|
||||
node.item.mask = TVIF_TEXT | TVIF_PARAM;
|
||||
node.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
||||
constexpr int count = static_cast<int>(std::size(settingsSections));
|
||||
const int image = data >= 0 && data < count ? static_cast<int>(data) : count;
|
||||
node.item.iImage = image;
|
||||
node.item.iSelectedImage = image + count + 1;
|
||||
node.item.pszText = const_cast<wchar_t *>(title);
|
||||
node.item.lParam = data;
|
||||
return TreeView_InsertItem(tree, &node);
|
||||
@@ -2443,6 +2539,7 @@ void resizeSettingsForDpi(HWND w, int previousDpi, int nextDpi)
|
||||
auto &v = *reinterpret_cast<SettingsView *>(GetWindowLongPtrW(w, GWLP_USERDATA));
|
||||
if (!v.ready) return;
|
||||
setSettingsFonts(w, v, nextDpi);
|
||||
refreshSettingsNavigationIcons(v, nextDpi);
|
||||
auto &layout = *windowLayoutState(v.viewport);
|
||||
layout.x = MulDiv(layout.x, nextDpi, previousDpi);
|
||||
layout.y = MulDiv(layout.y, nextDpi, previousDpi);
|
||||
@@ -3244,6 +3341,7 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
saveSettingsWindowState(w, *v);
|
||||
break;
|
||||
case WM_NCDESTROY:
|
||||
if (v->navigationIcons) ImageList_Destroy(v->navigationIcons);
|
||||
if (v->rawMouseRegistered) registerMouseTestInput(nullptr);
|
||||
for (HICON icon : v->mouseProfileChecks)
|
||||
if (icon) DestroyIcon(icon);
|
||||
|
||||
@@ -2,6 +2,10 @@ constexpr int RuleName = 783, RuleHotkey = 784, RuleExecutable = 785, RuleBrowse
|
||||
constexpr int RuleReuseWindow = 787, RuleNewInstance = 788, RuleRemove = 789;
|
||||
constexpr int RuleAction = 790, RuleControl = 791, RuleText = 792, RuleModeLabel = 793, RuleTextLabel = 794;
|
||||
constexpr int RulePickerHelp = 795;
|
||||
constexpr int RuleProgramLabel = 796, RuleUrl = 797, RuleUrlLabel = 798, RuleBrowser = 799, RuleBrowserLabel = 800;
|
||||
constexpr int RuleChromeProfile = 801, RuleChromeProfileLabel = 802, RuleBrowserPath = 803,
|
||||
RuleBrowserBrowse = 804, RuleBrowserPathLabel = 805;
|
||||
constexpr int ShortcutDialogWidth = 620, ShortcutDialogHeight = 425;
|
||||
|
||||
void fillCustomShortcuts(SettingsView &view, int selected = -1)
|
||||
{
|
||||
@@ -15,7 +19,8 @@ void fillCustomShortcuts(SettingsView &view, int selected = -1)
|
||||
item.iItem = row;
|
||||
item.pszText = const_cast<wchar_t *>(rule.name.c_str());
|
||||
ListView_InsertItem(list, &item);
|
||||
const wchar_t *action = rule.action == CustomShortcutAction::SendText ? L"Send text to app" :
|
||||
const wchar_t *action = rule.action == CustomShortcutAction::OpenUrl ? L"Open URL" :
|
||||
rule.action == CustomShortcutAction::SendText ? L"Send text to app" :
|
||||
rule.newInstance ? L"Launch new instance" : L"Activate last used or launch";
|
||||
ListView_SetItemText(list, row, 1, const_cast<wchar_t *>(action));
|
||||
ListView_SetItemText(list, row, 2, const_cast<wchar_t *>(rule.shortcut.c_str()));
|
||||
@@ -41,6 +46,9 @@ struct CustomShortcutEditor
|
||||
std::wstring targetExecutable;
|
||||
std::wstring launchExecutable;
|
||||
int controlId = 0;
|
||||
CustomShortcutAction action = CustomShortcutAction::LaunchApp;
|
||||
std::vector<std::pair<std::wstring, std::wstring>> chromeProfiles;
|
||||
bool profilesLoaded = false;
|
||||
};
|
||||
|
||||
void stageCustomShortcuts(SettingsView &view, std::vector<CustomShortcut> rules)
|
||||
@@ -49,20 +57,60 @@ void stageCustomShortcuts(SettingsView &view, std::vector<CustomShortcut> rules)
|
||||
view.draft.customShortcuts = std::move(proposed.customShortcuts);
|
||||
}
|
||||
|
||||
bool shortcutSendsText(HWND w)
|
||||
CustomShortcutAction selectedShortcutAction(HWND w)
|
||||
{
|
||||
return SendDlgItemMessageW(w, RuleAction, CB_GETCURSEL, 0, 0) == 1;
|
||||
return static_cast<CustomShortcutAction>(SendDlgItemMessageW(w, RuleAction, CB_GETCURSEL, 0, 0));
|
||||
}
|
||||
|
||||
void refreshCustomShortcutEditor(HWND w)
|
||||
ShortcutBrowser selectedShortcutBrowser(HWND w)
|
||||
{
|
||||
const bool sendsText = shortcutSendsText(w);
|
||||
return static_cast<ShortcutBrowser>(SendDlgItemMessageW(w, RuleBrowser, CB_GETCURSEL, 0, 0));
|
||||
}
|
||||
|
||||
void refreshCustomShortcutEditor(HWND w, CustomShortcutEditor &editor)
|
||||
{
|
||||
const bool sendsText = editor.action == CustomShortcutAction::SendText;
|
||||
const bool opensUrl = editor.action == CustomShortcutAction::OpenUrl;
|
||||
const bool chrome = opensUrl && selectedShortcutBrowser(w) == ShortcutBrowser::Chrome;
|
||||
const bool other = opensUrl && selectedShortcutBrowser(w) == ShortcutBrowser::Other;
|
||||
const auto picker = GetDlgItem(w, AppWindowPickerIcon);
|
||||
if (sendsText) SetPropW(picker, L"PickShortcutControl", reinterpret_cast<HANDLE>(1));
|
||||
else RemovePropW(picker, L"PickShortcutControl");
|
||||
for (const int id : {RuleProgramLabel, RuleExecutable, AppWindowPickerIcon, RulePickerHelp})
|
||||
ShowWindow(GetDlgItem(w, id), opensUrl ? SW_HIDE : SW_SHOWNA);
|
||||
for (const int id : {RuleControl, RuleTextLabel, RuleText}) ShowWindow(GetDlgItem(w, id), sendsText ? SW_SHOWNA : SW_HIDE);
|
||||
for (const int id : {RuleBrowse, RuleModeLabel, RuleReuseWindow, RuleNewInstance})
|
||||
ShowWindow(GetDlgItem(w, id), sendsText ? SW_HIDE : SW_SHOWNA);
|
||||
ShowWindow(GetDlgItem(w, id), sendsText || opensUrl ? SW_HIDE : SW_SHOWNA);
|
||||
for (const int id : {RuleUrl, RuleUrlLabel, RuleBrowser, RuleBrowserLabel})
|
||||
ShowWindow(GetDlgItem(w, id), opensUrl ? SW_SHOWNA : SW_HIDE);
|
||||
for (const int id : {RuleChromeProfile, RuleChromeProfileLabel})
|
||||
ShowWindow(GetDlgItem(w, id), chrome ? SW_SHOWNA : SW_HIDE);
|
||||
for (const int id : {RuleBrowserPath, RuleBrowserBrowse, RuleBrowserPathLabel})
|
||||
ShowWindow(GetDlgItem(w, id), other ? SW_SHOWNA : SW_HIDE);
|
||||
const auto browser = GetDlgItem(w, RuleBrowser);
|
||||
for (auto &[control, bounds] : windowLayoutState(w)->controls)
|
||||
if (control == browser) bounds.right = chrome ? 298 : 598;
|
||||
arrangeWindow(w);
|
||||
if (chrome && !editor.profilesLoaded)
|
||||
{
|
||||
editor.profilesLoaded = true;
|
||||
editor.chromeProfiles = chromeShortcutProfiles();
|
||||
const auto saved = editor.previous ? editor.previous->chromeProfile : std::wstring{};
|
||||
if (!saved.empty() && std::none_of(editor.chromeProfiles.begin(), editor.chromeProfiles.end(),
|
||||
[&](const auto &profile) { return profile.first == saved; }))
|
||||
editor.chromeProfiles.emplace_back(saved, saved + L" (unavailable)");
|
||||
int selected = 0, index = 0;
|
||||
for (const auto &[directory, name] : editor.chromeProfiles)
|
||||
{
|
||||
const bool duplicate = std::count_if(editor.chromeProfiles.begin(), editor.chromeProfiles.end(),
|
||||
[&](const auto &profile) { return profile.second == name; }) > 1;
|
||||
const auto caption = duplicate ? name + L" (" + directory + L")" : name;
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(caption.c_str()));
|
||||
++index;
|
||||
if (directory == saved) selected = index;
|
||||
}
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_SETCURSEL, selected, 0);
|
||||
}
|
||||
SendDlgItemMessageW(w, RuleExecutable, EM_SETREADONLY, sendsText, 0);
|
||||
value(w, RulePickerHelp, sendsText ? L"Drag the crosshair onto the text field you want to fill." :
|
||||
L"Drag the crosshair to an open window to select its program.");
|
||||
@@ -82,7 +130,7 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
const auto picked = reinterpret_cast<HWND>(wp);
|
||||
const auto root = GetAncestor(picked, GA_ROOT);
|
||||
const auto path = processImagePath(root);
|
||||
if (shortcutSendsText(w))
|
||||
if (editor->action == CustomShortcutAction::SendText)
|
||||
{
|
||||
const auto kind = shortcutTextControlClass(picked);
|
||||
const auto id = GetDlgCtrlID(picked);
|
||||
@@ -108,15 +156,21 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
const auto id = LOWORD(wp);
|
||||
if (id == RuleAction && HIWORD(wp) == CBN_SELCHANGE)
|
||||
{
|
||||
if (shortcutSendsText(w)) editor->launchExecutable = value(w, RuleExecutable);
|
||||
refreshCustomShortcutEditor(w);
|
||||
value(w, RuleExecutable, shortcutSendsText(w) ? editor->targetExecutable : editor->launchExecutable);
|
||||
if (editor->action == CustomShortcutAction::LaunchApp) editor->launchExecutable = value(w, RuleExecutable);
|
||||
editor->action = selectedShortcutAction(w);
|
||||
refreshCustomShortcutEditor(w, *editor);
|
||||
value(w, RuleExecutable, editor->action == CustomShortcutAction::SendText ? editor->targetExecutable : editor->launchExecutable);
|
||||
return 0;
|
||||
}
|
||||
if (id == RuleBrowse)
|
||||
if (id == RuleBrowser && HIWORD(wp) == CBN_SELCHANGE)
|
||||
{
|
||||
refreshCustomShortcutEditor(w, *editor);
|
||||
return 0;
|
||||
}
|
||||
if (id == RuleBrowse || id == RuleBrowserBrowse)
|
||||
{
|
||||
const auto path = chooseApplicationFile(w, L"Programs (*.exe)\0*.exe\0");
|
||||
if (!path.empty()) value(w, RuleExecutable, path);
|
||||
if (!path.empty()) value(w, id == RuleBrowse ? RuleExecutable : RuleBrowserPath, path);
|
||||
return 0;
|
||||
}
|
||||
if (id == IDOK || id == RuleRemove)
|
||||
@@ -131,7 +185,7 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
CustomShortcut rule{value(w, RuleName), value(w, RuleHotkey), value(w, RuleExecutable),
|
||||
row < 0 || rules[row].enabled, checked(w, RuleNewInstance)};
|
||||
if (shortcutSendsText(w))
|
||||
if (editor->action == CustomShortcutAction::SendText)
|
||||
{
|
||||
rule.action = CustomShortcutAction::SendText;
|
||||
rule.controlClass = editor->controlClass;
|
||||
@@ -142,6 +196,20 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (rule.controlClass.empty() || rule.text.empty())
|
||||
throw std::runtime_error("Choose a target text field and enter the text to insert.");
|
||||
}
|
||||
else if (editor->action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
rule.action = CustomShortcutAction::OpenUrl;
|
||||
rule.url = trimApplicationText(value(w, RuleUrl));
|
||||
rule.browser = selectedShortcutBrowser(w);
|
||||
rule.executable = rule.browser == ShortcutBrowser::Other ? trimApplicationText(value(w, RuleBrowserPath)) : L"";
|
||||
rule.newInstance = false;
|
||||
if (rule.browser == ShortcutBrowser::Chrome)
|
||||
{
|
||||
const auto profile = SendDlgItemMessageW(w, RuleChromeProfile, CB_GETCURSEL, 0, 0);
|
||||
if (profile > 0 && static_cast<size_t>(profile) <= editor->chromeProfiles.size())
|
||||
rule.chromeProfile = editor->chromeProfiles[profile - 1].first;
|
||||
}
|
||||
}
|
||||
if (row < 0) rules.push_back(std::move(rule));
|
||||
else rules[row] = std::move(rule);
|
||||
}
|
||||
@@ -182,12 +250,12 @@ void showCustomShortcut(HWND owner, SettingsView &view, bool editing)
|
||||
const int row = editing ? ListView_GetNextItem(list, -1, LVNI_SELECTED) : -1;
|
||||
if (editing && row < 0) return;
|
||||
const auto rule = editing ? view.draft.customShortcuts.at(row) : CustomShortcut{};
|
||||
const HWND w = makeWindow(*view.app, L"KSwitcher.CustomShortcut", editing ? L"Edit shortcut" : L"Add shortcut",
|
||||
customShortcutProc, 620, 425, 0, false, owner);
|
||||
windowLayoutState(w)->fixedClient = true;
|
||||
const HWND w = makeSettingsModal(*view.app, owner, L"KSwitcher.CustomShortcut", editing ? L"Edit shortcut" : L"Add shortcut",
|
||||
customShortcutProc, ShortcutDialogWidth, ShortcutDialogHeight);
|
||||
const bool sendsText = rule.action == CustomShortcutAction::SendText;
|
||||
auto *editor = new CustomShortcutEditor{view, row, editing ? std::optional(rule) : std::nullopt, nullptr, rule.controlClass,
|
||||
sendsText ? rule.executable : L"", sendsText ? L"" : rule.executable, rule.controlId};
|
||||
sendsText ? rule.executable : L"", rule.action == CustomShortcutAction::LaunchApp ? rule.executable : L"",
|
||||
rule.controlId, rule.action};
|
||||
SetWindowLongPtrW(w, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(editor));
|
||||
label(w, L"&Name", 22, 16, 340);
|
||||
edit(w, RuleName, 22, 40, 340);
|
||||
@@ -195,10 +263,10 @@ void showCustomShortcut(HWND owner, SettingsView &view, bool editing)
|
||||
hotkeyEdit(*view.app, w, RuleHotkey, 378, 40, 220);
|
||||
label(w, L"&Action", 22, 80, 576);
|
||||
control(w, WC_COMBOBOXW, L"", WS_TABSTOP | CBS_DROPDOWNLIST, RuleAction, 22, 101, 576, 110);
|
||||
for (const auto *action : {L"Launch app", L"Send text to app"})
|
||||
for (const auto *action : {L"Launch app", L"Send text to app", L"Open URL"})
|
||||
SendDlgItemMessageW(w, RuleAction, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(action));
|
||||
SendDlgItemMessageW(w, RuleAction, CB_SETCURSEL, sendsText, 0);
|
||||
label(w, L"&Program", 22, 137, 576);
|
||||
SendDlgItemMessageW(w, RuleAction, CB_SETCURSEL, static_cast<WPARAM>(rule.action), 0);
|
||||
control(w, L"STATIC", L"&Program", 0, RuleProgramLabel, 22, 137, 576, 22);
|
||||
edit(w, RuleExecutable, 22, 160, 440);
|
||||
button(w, L"&Browse...", RuleBrowse, 472, 158, 84);
|
||||
createAppWindowPicker(w, AppWindowPickerIcon, 566, 158, 32, editor->pickerOutline, createButtonTooltips(w));
|
||||
@@ -211,18 +279,34 @@ void showCustomShortcut(HWND owner, SettingsView &view, bool editing)
|
||||
control(w, L"BUTTON", L"Activate the last-used window, or launch the app if it is closed",
|
||||
WS_TABSTOP | WS_GROUP | BS_AUTORADIOBUTTON, RuleReuseWindow, 22, 252, 576, 24);
|
||||
control(w, L"BUTTON", L"Always launch a new instance", BS_AUTORADIOBUTTON, RuleNewInstance, 22, 281, 576, 24);
|
||||
if (editing) button(w, L"&Remove", RuleRemove, 22, 370, 90);
|
||||
control(w, L"BUTTON", editing ? L"Save shortcut" : L"Add shortcut", WS_TABSTOP | WS_GROUP | BS_DEFPUSHBUTTON,
|
||||
IDOK, 478, 370, 120, 28);
|
||||
button(w, L"Cancel", IDCANCEL, 376, 370, 90);
|
||||
control(w, L"STATIC", L"&URL", 0, RuleUrlLabel, 22, 137, 576, 22);
|
||||
edit(w, RuleUrl, 22, 160, 576);
|
||||
SendDlgItemMessageW(w, RuleUrl, EM_SETLIMITTEXT, 16384, 0);
|
||||
control(w, L"STATIC", L"&Browser", 0, RuleBrowserLabel, 22, 201, 276, 22);
|
||||
control(w, WC_COMBOBOXW, L"", WS_TABSTOP | CBS_DROPDOWNLIST, RuleBrowser, 22, 224, 576, 115);
|
||||
for (const auto *browser : {L"Default browser", L"Google Chrome", L"Other browser"})
|
||||
SendDlgItemMessageW(w, RuleBrowser, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(browser));
|
||||
SendDlgItemMessageW(w, RuleBrowser, CB_SETCURSEL, static_cast<WPARAM>(rule.browser), 0);
|
||||
control(w, L"STATIC", L"Chrome &profile", 0, RuleChromeProfileLabel, 319, 201, 279, 22);
|
||||
control(w, WC_COMBOBOXW, L"", WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST, RuleChromeProfile, 319, 224, 279, 122);
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Use Chrome's default profile"));
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_SETCURSEL, 0, 0);
|
||||
control(w, L"STATIC", L"Browser executable", 0, RuleBrowserPathLabel, 22, 265, 576, 22);
|
||||
edit(w, RuleBrowserPath, 22, 288, 478);
|
||||
button(w, L"Browse...", RuleBrowserBrowse, 510, 286, 88);
|
||||
settingsModalActions(w, ShortcutDialogWidth, ShortcutDialogHeight, editing ? L"Save shortcut" : L"Add shortcut",
|
||||
RuleRemove, editing ? L"&Remove" : nullptr);
|
||||
value(w, RuleName, rule.name);
|
||||
value(w, RuleHotkey, rule.shortcut);
|
||||
value(w, RuleExecutable, rule.executable);
|
||||
value(w, RuleControl, rule.controlClass.empty() ? L"No target field selected" :
|
||||
L"Target control: " + rule.controlClass + L" (ID " + std::to_wstring(rule.controlId) + L")");
|
||||
value(w, RuleText, rule.text);
|
||||
value(w, RuleUrl, rule.url);
|
||||
if (rule.action == CustomShortcutAction::OpenUrl && rule.browser == ShortcutBrowser::Other)
|
||||
value(w, RuleBrowserPath, rule.executable);
|
||||
CheckRadioButton(w, RuleReuseWindow, RuleNewInstance, rule.newInstance ? RuleNewInstance : RuleReuseWindow);
|
||||
refreshCustomShortcutEditor(w);
|
||||
refreshCustomShortcutEditor(w, *editor);
|
||||
EnableWindow(owner, FALSE);
|
||||
showRequestedWindow(w);
|
||||
SetFocus(GetDlgItem(w, RuleName));
|
||||
|
||||
@@ -364,6 +364,8 @@ void refreshLan(HWND w,LanView &v)
|
||||
auto mode=v.snapshot.value("controlMode",0);
|
||||
if(mode==2)inputStatus=L"Mouse and keyboard control the OTHER PC. Ctrl+Alt+Esc returns here.";
|
||||
else if(mode==3)inputStatus=L"This PC is controlled remotely. Local physical input takes control back.";
|
||||
const auto inputBlock=v.snapshot.value("inputBlock",std::string{});
|
||||
if(!inputBlock.empty()&&v.snapshot.value("shareInput",false))inputStatus=wide(inputBlock);
|
||||
if (v.draft.contains("shareInput"))
|
||||
inputStatus = L"Click Apply or Save to apply input sharing changes.";
|
||||
setStatus(718,v.layoutError.empty() ? inputStatus : v.layoutError);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.10";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.15";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
|
||||
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
|
||||
|
||||
@@ -23,10 +23,14 @@ int wmain(int argc,wchar_t **argv)
|
||||
wchar_t executable[32768]{};
|
||||
const auto length=GetModuleFileNameW(nullptr,executable,static_cast<DWORD>(std::size(executable)));
|
||||
if(!length || length>=std::size(executable)) return 1;
|
||||
const std::filesystem::path target=argc==2?argv[1]:executable;
|
||||
const bool browserFixture=argc==2 && std::filesystem::path(executable).filename()==L"browser-fixture.exe";
|
||||
const std::filesystem::path target=argc==2 && !browserFixture?argv[1]:executable;
|
||||
auto report=target;
|
||||
report+=L".opened";
|
||||
std::ofstream result(report,std::ios::binary);
|
||||
result<<"opened";
|
||||
if(browserFixture) {
|
||||
const std::wstring_view url(argv[1]);
|
||||
for(const auto ch:url) result.put(static_cast<char>(ch));
|
||||
} else result<<"opened";
|
||||
return result?0:1;
|
||||
}
|
||||
@@ -43,6 +43,40 @@ struct InputRegressionAccess {
|
||||
}
|
||||
for (const auto &job : jobs) job();
|
||||
}
|
||||
static bool probeTrayBlock(App &app)
|
||||
{
|
||||
const auto savedConnections = app.trayInput;
|
||||
const auto savedBlock = app.trayInputBlock;
|
||||
const auto savedPulse = app.trayInputPulse;
|
||||
const auto checkBadge = [&](bool blocked) {
|
||||
for (int size : {16, 32})
|
||||
{
|
||||
const auto icon = app.trayInputBadge(app.trayBaseIcon(size, size), size, size);
|
||||
const bool matches = app.inputState == App::InputState::Active ?
|
||||
trayIconMatchesLanBadge(icon, size, blocked) : !icon;
|
||||
if (icon) DestroyIcon(icon);
|
||||
if (!matches) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
app.trayInput = {1, 1, 1, false};
|
||||
app.trayInputBlock.clear();
|
||||
const bool ready = checkBadge(false);
|
||||
app.trayInputBlock = L"Cursor handoff blocked on this PC: Tab is held.";
|
||||
const bool blocked = checkBadge(true);
|
||||
app.trayInput = {1, 2, 2, false};
|
||||
app.trayInputPulse = false;
|
||||
const bool steadyDim = checkBadge(true);
|
||||
app.trayInputPulse = true;
|
||||
const bool steadyBright = checkBadge(true);
|
||||
app.trayInput = {1, 1, 1, false};
|
||||
app.trayInputBlock.clear();
|
||||
const bool restored = checkBadge(false);
|
||||
app.trayInput = savedConnections;
|
||||
app.trayInputBlock = savedBlock;
|
||||
app.trayInputPulse = savedPulse;
|
||||
return ready && blocked && steadyDim && steadyBright && restored;
|
||||
}
|
||||
static LRESULT CALLBACK probeInput(HWND w, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR context) {
|
||||
auto &app = *reinterpret_cast<App *>(context);
|
||||
static bool queuedSnippet = false;
|
||||
@@ -50,6 +84,7 @@ struct InputRegressionAccess {
|
||||
if (msg == WM_EXITMENULOOP && app.inputState == App::InputState::Active)
|
||||
queuedSnippet = app.queueSnippet(w, 0, 2, w);
|
||||
if (msg == ProbeTrayIcon) return trayIconMatchesInput(app.trayBaseIcon(16, 16), wp != 0);
|
||||
if (msg == ProbeTrayBlock) return probeTrayBlock(app);
|
||||
if (msg != ProbeInputState) return DefSubclassProc(w, msg, wp, lp);
|
||||
// Also exercise settings/layout updates that would normally re-register shortcuts.
|
||||
if (wp && app.inputState == App::InputState::Paused) {
|
||||
@@ -301,11 +336,26 @@ static void historyLayoutChecks(ks::App &app, const std::filesystem::path &temp,
|
||||
require(SendDlgItemMessageW(history,102,LB_GETCURSEL,0,0)==0 &&
|
||||
SendDlgItemMessageW(history,102,LB_GETTOPINDEX,0,0)==0,
|
||||
"fresh history invocation selects and reveals newest screenshot instead of saved selection");
|
||||
SendDlgItemMessageW(history,102,LB_SETCURSEL,2,0);
|
||||
app.history->add(ks::textClip(L"background clipboard update"),L"test",app.settings);
|
||||
ks::refreshHistory(app);
|
||||
require(pumpUntil(4),"background refresh loads a new item");
|
||||
require(SendDlgItemMessageW(history,102,LB_GETCURSEL,0,0)==3,
|
||||
"background refresh preserves the selected record while browsing");
|
||||
SendDlgItemMessageW(history,102,LB_SETTOPINDEX,0,0);
|
||||
screenshot.bgra[0] ^= 1;
|
||||
app.history->add(ks::Clip{{ks::imageDib(screenshot)}},L"new screenshot",app.settings);
|
||||
ks::refreshHistory(app);
|
||||
require(pumpUntil(5),"open history loads the new screenshot");
|
||||
require(SendDlgItemMessageW(history,102,LB_GETTOPINDEX,0,0)==0,
|
||||
"history at the top immediately shows the new screenshot");
|
||||
require(SendDlgItemMessageW(history,102,LB_GETCURSEL,0,0)==4,
|
||||
"showing a new screenshot preserves the selection");
|
||||
if (capturePreview)
|
||||
{
|
||||
RedrawWindow(history, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
|
||||
ks::InputRegressionAccess::finishHistoryPreviews(app);
|
||||
pumpUntil(3);
|
||||
pumpUntil(5);
|
||||
RedrawWindow(history, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
|
||||
RECT historyClient{};
|
||||
GetClientRect(history, &historyClient);
|
||||
@@ -315,12 +365,13 @@ static void historyLayoutChecks(ks::App &app, const std::filesystem::path &temp,
|
||||
ks::atomicWrite(std::filesystem::path(ks::executable()).parent_path() / L"clipboard-history.png",
|
||||
ks::encodePng(ks::decodeImage(preview)));
|
||||
}
|
||||
SendDlgItemMessageW(history,102,LB_SETCURSEL,2,0);
|
||||
app.history->add(ks::textClip(L"background clipboard update"),L"test",app.settings);
|
||||
SendDlgItemMessageW(history,102,LB_SETTOPINDEX,1,0);
|
||||
require(SendDlgItemMessageW(history,102,LB_GETTOPINDEX,0,0)==1,
|
||||
"history can scroll past the newest item");
|
||||
app.history->add(ks::textClip(L"another clipboard update"),L"test",app.settings);
|
||||
ks::refreshHistory(app);
|
||||
require(pumpUntil(4),"background refresh loads a new item");
|
||||
require(SendDlgItemMessageW(history,102,LB_GETCURSEL,0,0)==3,
|
||||
"background refresh preserves the selected record while browsing");
|
||||
require(pumpUntil(6) && SendDlgItemMessageW(history,102,LB_GETTOPINDEX,0,0)==2,
|
||||
"history preserves the top record when scrolled down");
|
||||
ShowWindow(history,SW_HIDE);
|
||||
}
|
||||
auto childRect=[&](int id) { RECT r{}; GetWindowRect(GetDlgItem(history,id),&r); MapWindowPoints(nullptr,history,(POINT*)&r,2); return r; };
|
||||
@@ -350,6 +401,36 @@ static void historyLayoutChecks(ks::App &app, const std::filesystem::path &temp,
|
||||
}
|
||||
DestroyWindow(history);
|
||||
}
|
||||
struct NavigationIconProbe
|
||||
{
|
||||
int commands{}, visibleIcons{}, submenus{};
|
||||
};
|
||||
|
||||
LRESULT CALLBACK inspectTrayMenu(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR data)
|
||||
{
|
||||
auto &probe = *reinterpret_cast<NavigationIconProbe *>(data);
|
||||
if (message == WM_INITMENUPOPUP && !probe.commands)
|
||||
{
|
||||
const auto menu = reinterpret_cast<HMENU>(wp);
|
||||
for (int i = 0; i < GetMenuItemCount(menu); ++i)
|
||||
{
|
||||
MENUITEMINFOW item{sizeof(item), MIIM_FTYPE | MIIM_BITMAP | MIIM_SUBMENU};
|
||||
if (!GetMenuItemInfoW(menu, i, TRUE, &item) || (item.fType & MFT_SEPARATOR)) continue;
|
||||
++probe.commands;
|
||||
if (item.hSubMenu) ++probe.submenus;
|
||||
DIBSECTION bitmap{};
|
||||
if (!item.hbmpItem || GetObjectW(item.hbmpItem, sizeof(bitmap), &bitmap) != sizeof(bitmap))
|
||||
continue;
|
||||
const auto *pixels = static_cast<const std::uint32_t *>(bitmap.dsBm.bmBits);
|
||||
if (pixels && std::any_of(pixels, pixels + bitmap.dsBm.bmWidth * bitmap.dsBm.bmHeight,
|
||||
[](std::uint32_t pixel) { return (pixel >> 24) != 0; }))
|
||||
++probe.visibleIcons;
|
||||
}
|
||||
}
|
||||
if (message == WM_ENTERIDLE && wp == MSGF_MENU) EndMenu();
|
||||
return DefSubclassProc(window, message, wp, lp);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 2 && std::string(argv[1]) == "--input-pause") return testInputPause();
|
||||
if (argc == 2 && std::string(argv[1]) == "--input-pause-resident") {
|
||||
@@ -379,6 +460,71 @@ int main(int argc, char **argv) {
|
||||
try {
|
||||
INITCOMMONCONTROLSEX controls{sizeof(controls),ICC_STANDARD_CLASSES|ICC_LISTVIEW_CLASSES};
|
||||
InitCommonControlsEx(&controls);
|
||||
if ((argc == 2 || argc == 3) && std::string_view(argv[1]) == "--navigation-icons")
|
||||
{
|
||||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
{
|
||||
ks::App app(GetModuleHandleW(nullptr), true, temp);
|
||||
ks::showSettings(app, false);
|
||||
const auto settings = app.settingsWindow;
|
||||
const auto tree = settingsNavigation(settings);
|
||||
const int pages = TreeView_GetCount(tree);
|
||||
require(pages == 22, "all Settings sections are listed");
|
||||
const auto images = TreeView_GetImageList(tree, TVSIL_NORMAL);
|
||||
require(images && ImageList_GetImageCount(images) >= 2 * pages, "normal and selected icons are loaded");
|
||||
for (int page = 0; page < pages; ++page)
|
||||
{
|
||||
TVITEMW item{};
|
||||
item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
||||
item.hItem = settingsSection(tree, page);
|
||||
require(item.hItem && TreeView_GetItem(tree, &item) && item.iImage >= 0 &&
|
||||
item.iImage < pages && item.iSelectedImage >= pages,
|
||||
"each Settings section has both icon states");
|
||||
}
|
||||
NavigationIconProbe probe;
|
||||
if (argc == 3)
|
||||
{
|
||||
const std::filesystem::path previewDirectory(ks::wide(argv[2]));
|
||||
std::filesystem::create_directories(previewDirectory);
|
||||
RECT frame{};
|
||||
GetWindowRect(settings, &frame);
|
||||
MONITORINFO monitor{sizeof(monitor)};
|
||||
if (GetMonitorInfoW(MonitorFromWindow(settings, MONITOR_DEFAULTTONEAREST), &monitor))
|
||||
{
|
||||
const int height = std::min<int>(monitor.rcWork.bottom - monitor.rcWork.top,
|
||||
MulDiv(900, GetDpiForWindow(settings), USER_DEFAULT_SCREEN_DPI));
|
||||
SetWindowPos(settings, nullptr, frame.left, std::min<int>(frame.top, monitor.rcWork.bottom - height),
|
||||
frame.right - frame.left, height, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
selectSettingsPage(settings, 12);
|
||||
ShowWindow(settings, SW_SHOWNOACTIVATE);
|
||||
RedrawWindow(settings, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
|
||||
RECT client{};
|
||||
GetClientRect(settings, &client);
|
||||
if (const auto dc = GetDC(settings))
|
||||
{
|
||||
const auto capture = ks::screenshotClip(dc, client.right, client.bottom, {});
|
||||
ReleaseDC(settings, dc);
|
||||
ks::atomicWrite(previewDirectory / L"settings-navigation.png",
|
||||
ks::encodePng(ks::decodeImage(capture)));
|
||||
}
|
||||
}
|
||||
app.window = CreateWindowExW(WS_EX_TOOLWINDOW, L"STATIC", L"", WS_POPUP,
|
||||
0, 0, 1, 1, nullptr, nullptr, app.instance, nullptr);
|
||||
require(app.window && SetWindowSubclass(app.window, inspectTrayMenu, 1,
|
||||
reinterpret_cast<DWORD_PTR>(&probe)), "can inspect native tray popup");
|
||||
app.trayMenu();
|
||||
require(probe.commands == 17 && probe.visibleIcons == probe.commands && probe.submenus == 3,
|
||||
"all tray commands and submenu parents have visible icon pixels");
|
||||
DestroyWindow(app.window);
|
||||
app.window = nullptr;
|
||||
DestroyWindow(settings);
|
||||
}
|
||||
CoUninitialize();
|
||||
std::filesystem::remove_all(temp);
|
||||
std::cout << "Passed " << checks << " navigation icon checks\n";
|
||||
return 0;
|
||||
}
|
||||
if (argc == 3 && std::string_view(argv[1]) == "--custom-shortcut-layout")
|
||||
{
|
||||
{
|
||||
@@ -423,7 +569,30 @@ int main(int argc, char **argv) {
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 753)) && IsWindowVisible(GetDlgItem(dialog, 792)) &&
|
||||
!IsWindowVisible(GetDlgItem(dialog, 787)),
|
||||
"text insertion uses the crosshair and shows a multiline text editor");
|
||||
DestroyWindow(dialog);
|
||||
auto select = [&](int id, int row) {
|
||||
SendDlgItemMessageW(dialog, id, CB_SETCURSEL, row, 0);
|
||||
SendMessageW(dialog, WM_COMMAND, MAKEWPARAM(id, CBN_SELCHANGE), 0);
|
||||
};
|
||||
select(790, 2);
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 797)) && IsWindowVisible(GetDlgItem(dialog, 799)) &&
|
||||
!IsWindowVisible(GetDlgItem(dialog, 753)) && !IsWindowVisible(GetDlgItem(dialog, 801)),
|
||||
"Open URL shows an address and browser without an unrelated crosshair or profile picker");
|
||||
select(799, 2);
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 803)), "choosing another browser exposes the browser executable");
|
||||
select(799, 1);
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 801)) && !IsWindowVisible(GetDlgItem(dialog, 803)),
|
||||
"choosing Chrome exposes the profile picker");
|
||||
SetDlgItemTextW(dialog, 783, L"Open project board");
|
||||
SetDlgItemTextW(dialog, 784, L"Ctrl+Alt+F10");
|
||||
SetDlgItemTextW(dialog, 797, L"https://example.com/board");
|
||||
SendMessageW(dialog, WM_COMMAND, IDOK, 0);
|
||||
require(!IsWindow(dialog) && ListView_GetItemCount(list) == 2, "adding Open URL updates the shortcut list");
|
||||
ListView_SetCheckState(list, 1, FALSE);
|
||||
SendMessageW(settings, WM_COMMAND, 272, 0);
|
||||
const auto persisted = ks::loadSettings(temp / L"settings.json", app.layouts).customShortcuts;
|
||||
require(persisted.size() == 2 && persisted[1].action == ks::CustomShortcutAction::OpenUrl &&
|
||||
persisted[1].url == L"https://example.com/board" && persisted[1].browser == ks::ShortcutBrowser::Chrome,
|
||||
"Apply persists the Open URL action and browser from the editor");
|
||||
DestroyWindow(settings);
|
||||
|
||||
const auto target = CreateWindowExW(0, L"STATIC", L"Shortcut target", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
@@ -468,6 +637,22 @@ int main(int argc, char **argv) {
|
||||
require(std::filesystem::exists(marker), newInstance ? "new-instance mode starts the program" :
|
||||
"activate mode starts the program if there is no matching window");
|
||||
}
|
||||
const auto browser = temp / L"browser-fixture.exe";
|
||||
std::filesystem::copy_file(std::filesystem::path(argv[2]), browser);
|
||||
const std::wstring url = L"https://example.com/board?view=a%20b&filter=active#notes";
|
||||
app.settings.customShortcuts[0] = {L"Open board", L"Ctrl+Alt+F9", browser.wstring(), true, false,
|
||||
ks::CustomShortcutAction::OpenUrl, L"", L"", 0, url, ks::ShortcutBrowser::Other};
|
||||
ks::InputRegressionAccess::invokeCustomShortcut(app, 0, VK_F9);
|
||||
const auto marker = temp / L"browser-fixture.exe.opened";
|
||||
for (const auto deadline = GetTickCount64() + 5000; GetTickCount64() < deadline;)
|
||||
{
|
||||
std::error_code ec;
|
||||
if (std::filesystem::file_size(marker, ec) == url.size()) break;
|
||||
Sleep(25);
|
||||
}
|
||||
const auto recorded = ks::readFile(marker, 1024);
|
||||
require(std::string(recorded.begin(), recorded.end()) == ks::utf8(url),
|
||||
"URL shortcut starts the chosen browser with the complete address as one argument");
|
||||
}
|
||||
std::filesystem::remove_all(temp);
|
||||
std::cout << "Passed " << checks << " custom shortcuts layout checks\n";
|
||||
|
||||
@@ -48,7 +48,7 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
std::wstring_view(label).starts_with(expected), "incorrect input state in tray menu");
|
||||
HMENU help{};
|
||||
MENUITEMINFOW donation{sizeof(donation), MIIM_BITMAP};
|
||||
bool donationSeparated = false;
|
||||
bool donationSeparated = false, resetAvailable = false;
|
||||
const auto menuTitle = [&](HMENU source, int index) {
|
||||
if (!GetMenuStringW(source, index, label, std::size(label), MF_BYPOSITION)) return std::wstring_view{};
|
||||
const std::wstring_view text(label);
|
||||
@@ -56,6 +56,8 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
};
|
||||
for (int i = 0, count = GetMenuItemCount(menu); i < count; ++i) {
|
||||
const auto title = menuTitle(menu, i);
|
||||
if (title == L"Reset held keys and mouse buttons" || title == L"Скинути затиснуті клавіші й кнопки миші")
|
||||
resetAvailable = (GetMenuState(menu, i, MF_BYPOSITION) & (MF_GRAYED | MF_DISABLED)) == 0;
|
||||
if (title == L"&Donate via Monobank" && i > 0 && i + 1 < count) {
|
||||
donationSeparated = (GetMenuState(menu, i - 1, MF_BYPOSITION) & MF_SEPARATOR) &&
|
||||
(GetMenuState(menu, i + 1, MF_BYPOSITION) & MF_SEPARATOR);
|
||||
@@ -66,6 +68,7 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
break;
|
||||
}
|
||||
}
|
||||
require(resetAvailable, "the tray offers manual input reset while active or paused");
|
||||
require(donationSeparated && donation.hbmpItem, "tray donation item has an icon and both separators");
|
||||
require(help && GetMenuItemCount(help) == 3 && menuTitle(help, 0) == L"&User guide" &&
|
||||
menuTitle(help, 1) == ks::whatsNewTitle(GetThreadUILanguage()) &&
|
||||
@@ -77,28 +80,51 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
}
|
||||
}
|
||||
|
||||
bool trayIconMatchesInput(HICON icon, bool active)
|
||||
namespace {
|
||||
template<class Check> bool renderedTrayIconMatches(HICON icon, int size, Check check)
|
||||
{
|
||||
HDC dc = CreateCompatibleDC(nullptr);
|
||||
HBITMAP bitmap = CreateBitmap(16, 16, 1, 32, nullptr);
|
||||
HBITMAP bitmap = CreateBitmap(size, size, 1, 32, nullptr);
|
||||
bool matches = false;
|
||||
if (dc && bitmap) {
|
||||
const auto previous = SelectObject(dc, bitmap);
|
||||
if (icon && DrawIconEx(dc, 0, 0, icon, 16, 16, 0, nullptr, DI_NORMAL)) {
|
||||
const auto tile = GetPixel(dc, 2, 8);
|
||||
const auto white = RGB(255, 255, 255);
|
||||
const auto gap = GetPixel(dc, 8, 8);
|
||||
// The active keycap is purple. The pause glyph has two white strokes with a gap.
|
||||
matches = active ? GetBValue(tile) > GetRValue(tile) + 70 :
|
||||
GetPixel(dc, 5, 8) == white && GetPixel(dc, 10, 8) == white &&
|
||||
GetRValue(gap) < 160 && std::abs(GetBValue(gap) - GetRValue(gap)) < 32;
|
||||
}
|
||||
if (icon && DrawIconEx(dc, 0, 0, icon, size, size, 0, nullptr, DI_NORMAL)) matches = check(dc);
|
||||
SelectObject(dc, previous);
|
||||
}
|
||||
if (bitmap) DeleteObject(bitmap);
|
||||
if (dc) DeleteDC(dc);
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
||||
bool trayIconMatchesInput(HICON icon, bool active)
|
||||
{
|
||||
return renderedTrayIconMatches(icon, 16, [active](HDC dc) {
|
||||
const auto tile = GetPixel(dc, 2, 8);
|
||||
const auto white = RGB(255, 255, 255);
|
||||
const auto gap = GetPixel(dc, 8, 8);
|
||||
// The active keycap is purple. The pause glyph has two white strokes with a gap.
|
||||
return active ? GetBValue(tile) > GetRValue(tile) + 70 :
|
||||
GetPixel(dc, 5, 8) == white && GetPixel(dc, 10, 8) == white &&
|
||||
GetRValue(gap) < 160 && std::abs(GetBValue(gap) - GetRValue(gap)) < 32;
|
||||
});
|
||||
}
|
||||
|
||||
bool trayIconMatchesLanBadge(HICON icon, int size, bool blocked)
|
||||
{
|
||||
return renderedTrayIconMatches(icon, size, [=](HDC dc) {
|
||||
if (!blocked)
|
||||
{
|
||||
const int center = size - 1 - 3 * size / 16;
|
||||
return GetPixel(dc, center, center) == RGB(69, 213, 140);
|
||||
}
|
||||
const int center = size - 1 - size / 4;
|
||||
const auto amber = RGB(255, 196, 87), ink = RGB(36, 36, 36);
|
||||
return GetPixel(dc, center - size / 8, center) == amber &&
|
||||
GetPixel(dc, center, center) == ink && GetPixel(dc, center, center + 1) == amber &&
|
||||
GetPixel(dc, center, center + size / 8) == ink;
|
||||
});
|
||||
}
|
||||
|
||||
int testInputPause()
|
||||
{
|
||||
@@ -126,6 +152,7 @@ int testInputPause()
|
||||
return resident && query(resident, ProbeInputState) == 1;
|
||||
}, "resident did not start with both hooks and shortcuts");
|
||||
require(query(resident, ProbeTrayIcon, TRUE), "active tray icon missing at startup");
|
||||
require(query(resident, ProbeTrayBlock), "tray shows a distinct warning during a LAN handoff block and restores green afterward");
|
||||
constexpr UINT mods = MOD_CONTROL | MOD_SHIFT;
|
||||
require(!RegisterHotKey(nullptr, 1, mods, VK_F23) && GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED,
|
||||
"Files shortcut should be owned by resident before pause");
|
||||
@@ -133,6 +160,7 @@ int testInputPause()
|
||||
until([&] { return query(resident, ProbeInputState) == 2; },
|
||||
"pause did not release both hooks and bindings and cancel the queued snippet");
|
||||
require(query(resident, ProbeTrayIcon), "pause bars missing after pause");
|
||||
require(query(resident, ProbeTrayBlock), "the handoff warning does not cover the paused tray icon");
|
||||
require(RegisterHotKey(nullptr, 1, mods, VK_F23), "another process could not acquire Files shortcut");
|
||||
require(query(resident, ProbeInputState, 1) == 2, "settings, layout reload or IPC restarted input");
|
||||
chooseInputAction(resident, child.dwProcessId, L"Resume &input processing");
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
|
||||
inline constexpr UINT ProbeInputState = WM_APP + 200;
|
||||
inline constexpr UINT ProbeTrayIcon = WM_APP + 201;
|
||||
inline constexpr UINT ProbeTrayBlock = WM_APP + 202;
|
||||
bool trayIconMatchesInput(HICON icon, bool active);
|
||||
bool trayIconMatchesLanBadge(HICON icon, int size, bool blocked);
|
||||
int testInputPause();
|
||||
@@ -13,7 +13,8 @@ void check(bool value,const char *text){if(!value)throw std::runtime_error(text)
|
||||
template<class F>void rejects(F f,const char *text){bool failed=false;try{f();}catch(...){failed=true;}check(failed,text);}
|
||||
struct Desktop
|
||||
{
|
||||
RECT rect{-1920,-200,0,880};POINT point{-1000,300};bool available=true,physicalHeld=false,allow=true;
|
||||
RECT rect{-1920,-200,0,880};POINT point{-1000,300};bool available=true,allow=true;
|
||||
int heldKey{};
|
||||
std::vector<INPUT> events;int dpi=96;bool delayed=false;InputRouter *router{};
|
||||
InputEnvironment environment()
|
||||
{
|
||||
@@ -26,7 +27,7 @@ struct Desktop
|
||||
if(router){MSLLHOOKSTRUCT m{};m.pt=point;m.flags=LLMHF_INJECTED;m.dwExtraInfo=i.mi.dwExtraInfo;router->mouse(WM_MOUSEMOVE,m,1000);}
|
||||
}
|
||||
return true;
|
||||
},[this]{return available;},[this]{return physicalHeld;},{},{},[this](POINT){return dpi;}};
|
||||
},[this]{return available;},[this]{return heldKey;},{},{},[this](POINT){return dpi;}};
|
||||
}
|
||||
unsigned keyEvents(bool down)const
|
||||
{return unsigned(std::count_if(events.begin(),events.end(),[down](auto &i){return i.type==INPUT_KEYBOARD&&bool(i.ki.dwFlags&KEYEVENTF_KEYUP)!=down;}));}
|
||||
@@ -205,9 +206,9 @@ void routerChecks()
|
||||
p.b.available=true;p.right.tick(true,1400);check(p.b.keyEvents(false)==1,"blocked release retried when normal desktop returns");
|
||||
}
|
||||
{
|
||||
Pair p(1);p.a.physicalHeld=true;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1000);
|
||||
Pair p(1);p.a.heldKey=VK_TAB;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1000);
|
||||
check(p.left.mode()==ControlMode::Local,"no cross-screen handoff with physically held key/button");
|
||||
p.a.physicalHeld=false;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1100);
|
||||
p.a.heldKey=0;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1100);
|
||||
p.left.keyboard(key('X'),true,1101);p.deliver(1200);
|
||||
check(p.left.mode()==ControlMode::Local&&p.right.mode()==ControlMode::Local,"typing during handoff cancels stale accept");
|
||||
}
|
||||
@@ -249,6 +250,7 @@ struct MeshFixture
|
||||
struct Message{std::string from,to;InputFrame frame;};
|
||||
std::deque<Message> messages;Desktop desktops[3];std::unique_ptr<InputMesh> meshes[3];uint64_t now=1000;
|
||||
std::map<std::string,uint64_t> connections[3];
|
||||
std::array<int,3> resets{};
|
||||
MeshFixture(bool vertical=false){
|
||||
POINT cells[3]={{0,0},{1,0},vertical?POINT{1,-1}:POINT{2,0}};
|
||||
for(int i=0;i<3;++i){
|
||||
@@ -259,7 +261,13 @@ struct MeshFixture
|
||||
}
|
||||
~MeshFixture(){for(auto &m:meshes)m.reset();}
|
||||
void pump(){for(int rounds=0;rounds<10;++rounds){
|
||||
while(!messages.empty()){auto m=messages.front();messages.pop_front();meshes[std::stoi(m.to)]->receive(m.from,m.frame,now);}
|
||||
while(!messages.empty()){
|
||||
auto m=messages.front();messages.pop_front();
|
||||
const int to=std::stoi(m.to);
|
||||
meshes[to]->receive(m.from,m.frame,now,true,[&,to]{
|
||||
++resets[to];desktops[to].heldKey=0;meshes[to]->forgetHeldKeys();
|
||||
});
|
||||
}
|
||||
for(int i=0;i<3;++i)meshes[i]->tick(connections[i],now);
|
||||
}}
|
||||
void move(int x,int y){++now;auto &d=desktops[0];auto old=d.point;MSLLHOOKSTRUCT m{};m.pt={old.x+x,old.y+y};d.point=m.pt;
|
||||
@@ -298,6 +306,118 @@ void meshChecks()
|
||||
f.connections[0]["2"]=2;f.pump();check(f.meshes[0]->mode()==ControlMode::Local,"new connection generation does not continue stale ownership");
|
||||
}
|
||||
}
|
||||
void handoffBlockChecks()
|
||||
{
|
||||
for(int blockedPc:{0,1})
|
||||
for(int heldKey:{VK_TAB,VK_LBUTTON,UnknownHeldInput})
|
||||
{
|
||||
MeshFixture f;
|
||||
f.desktops[blockedPc].heldKey=heldKey;
|
||||
f.desktops[0].point={798,300};
|
||||
f.move(1,0);
|
||||
const auto sourceBlock=f.meshes[0]->handoffBlock();
|
||||
const auto blockedPcBlock=f.meshes[blockedPc]->handoffBlock();
|
||||
check(f.meshes[0]->mode()==ControlMode::Local&&sourceBlock.key==heldKey&&
|
||||
sourceBlock.peer==(blockedPc==0?"":"1")&&blockedPcBlock.key==heldKey&&blockedPcBlock.peer.empty(),
|
||||
"held input blocks the handoff and names the PC that is holding it");
|
||||
f.desktops[blockedPc].heldKey=0;
|
||||
f.pump();
|
||||
check(!f.meshes[0]->handoffBlock().key&&!f.meshes[blockedPc]->handoffBlock().key,
|
||||
"release clears both notices without another crossing attempt");
|
||||
f.now+=650;
|
||||
f.enter();
|
||||
}
|
||||
{
|
||||
MeshFixture f;
|
||||
f.meshes[1]->keyboard(key(VK_MEDIA_PLAY_PAUSE),true,f.now);
|
||||
f.desktops[1].heldKey=VK_MEDIA_PLAY_PAUSE;
|
||||
f.desktops[0].point={798,300};
|
||||
f.move(1,0);
|
||||
check(f.meshes[0]->handoffBlock().key==VK_MEDIA_PLAY_PAUSE,"tracked media key reports the Windows key identity");
|
||||
f.desktops[1].heldKey=0;
|
||||
f.meshes[1]->forgetHeldKeys();
|
||||
f.pump();
|
||||
check(!f.meshes[0]->handoffBlock().key&&!f.meshes[1]->handoffBlock().key,
|
||||
"manual reset also clears previously tracked held keys");
|
||||
f.now+=650;
|
||||
f.enter();
|
||||
}
|
||||
{
|
||||
MeshFixture f;
|
||||
f.desktops[1].heldKey=VK_TAB;
|
||||
f.desktops[0].point={798,300};
|
||||
f.move(1,0);
|
||||
f.desktops[1].heldKey=VK_XBUTTON2;
|
||||
f.pump();
|
||||
check(f.meshes[0]->handoffBlock().key==VK_XBUTTON2,"source notice updates when the destination blocker changes");
|
||||
f.connections[0]["1"]=2;
|
||||
f.pump();
|
||||
check(!f.meshes[0]->handoffBlock().key,"a reconnect discards notices from the prior connection generation");
|
||||
}
|
||||
}
|
||||
void heldInputReleaseChecks()
|
||||
{
|
||||
const auto releases=heldInputReleases([](int key){
|
||||
return key==VK_MEDIA_PLAY_PAUSE||key==VK_LBUTTON||key==VK_XBUTTON2||key==VK_CONTROL||key==VK_RCONTROL;
|
||||
});
|
||||
check(releases.size()==4,"reset includes only down inputs and does not duplicate a generic modifier");
|
||||
check(releases[0].type==INPUT_MOUSE&&releases[0].mi.dwFlags==MOUSEEVENTF_LEFTUP&&
|
||||
releases[0].mi.dwExtraInfo==inputMarker(),"reset releases the left mouse button without running mouse bindings");
|
||||
check(releases[1].type==INPUT_MOUSE&&releases[1].mi.dwFlags==MOUSEEVENTF_XUP&&
|
||||
releases[1].mi.mouseData==XBUTTON2,"reset releases the correct extra mouse button");
|
||||
check(releases[2].type==INPUT_KEYBOARD&&releases[2].ki.wVk==VK_RCONTROL&&
|
||||
(releases[2].ki.dwFlags&KEYEVENTF_KEYUP),"reset releases the specific modifier");
|
||||
check(releases[3].type==INPUT_KEYBOARD&&releases[3].ki.wVk==VK_MEDIA_PLAY_PAUSE&&
|
||||
releases[3].ki.dwFlags==(KEYEVENTF_KEYUP|KEYEVENTF_EXTENDEDKEY)&&releases[3].ki.dwExtraInfo==inputMarker(),
|
||||
"reset releases Play/Pause without generating a media key press");
|
||||
check(heldInputName(VK_TAB)==L"Tab"&&heldInputName(VK_MEDIA_PLAY_PAUSE)==L"Play/Pause"&&
|
||||
heldInputName(VK_LBUTTON)==L"Left mouse button"&&heldInputName(UnknownHeldInput).empty(),
|
||||
"known blockers have readable names and unknown ones use the general message");
|
||||
check(heldInputReleases([](int){return false;}).empty(),"reset with no down inputs is a no-op");
|
||||
}
|
||||
void pairedInputResetChecks()
|
||||
{
|
||||
Desktop desktop;
|
||||
std::vector<std::pair<std::string,InputFrame>> sent;
|
||||
InputMesh mesh("local",desktop.environment(),{},[&](const auto &peer,auto frame){
|
||||
sent.emplace_back(peer,frame);return true;
|
||||
});
|
||||
mesh.tick({{"first",1},{"second",2},{"forgotten",3}},1000);
|
||||
mesh.requestHeldInputReset([](const auto &peer){return peer!="forgotten";});
|
||||
check(sent==std::vector<std::pair<std::string,InputFrame>>{
|
||||
{"first",ResetHeldInputRequest},{"second",ResetHeldInputRequest}},
|
||||
"one reset goes to every connected pair, including computers outside the monitor layout");
|
||||
|
||||
int resets=0;
|
||||
const auto reset=[&]{++resets;};
|
||||
mesh.receive("offline",ResetHeldInputRequest,1001,true,reset);
|
||||
mesh.receive("first",ResetHeldInputRequest,1002,false,reset);
|
||||
auto wrong=ResetHeldInputRequest;
|
||||
wrong.b=VK_TAB;
|
||||
mesh.receive("first",wrong,1003,true,reset);
|
||||
check(!resets,"offline, blocked, and malformed messages cannot reset this computer");
|
||||
mesh.receive("first",ResetHeldInputRequest,1004,true,reset);
|
||||
check(resets==1&&sent.size()==2,"an authenticated reset is applied locally without being forwarded");
|
||||
|
||||
Pair old(1);
|
||||
old.enter(1);
|
||||
old.right.receive(ResetHeldInputRequest,1200);
|
||||
check(old.right.mode()==ControlMode::Receiving&&old.ba.empty(),
|
||||
"legacy input routers ignore the zero-token reset even during remote control");
|
||||
|
||||
MeshFixture three;
|
||||
three.desktops[1].heldKey=VK_TAB;
|
||||
three.desktops[2].heldKey=VK_LBUTTON;
|
||||
three.desktops[0].point={798,300};
|
||||
three.move(1,0);
|
||||
check(three.meshes[0]->handoffBlock().peer=="1","the source sees the first destination block the handoff");
|
||||
three.meshes[0]->requestHeldInputReset([](const auto &){return true;});
|
||||
three.pump();
|
||||
check(three.resets==std::array{0,1,1}&&!three.meshes[0]->handoffBlock().key&&!three.desktops[2].heldKey,
|
||||
"one request clears the block and resets the other idle paired PC without another action");
|
||||
three.now+=650;
|
||||
three.enter();
|
||||
}
|
||||
uint16_t freePort()
|
||||
{
|
||||
SOCKET s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);if(s==INVALID_SOCKET)throw std::runtime_error("test socket");
|
||||
@@ -492,6 +612,7 @@ void channelChecks()
|
||||
auto next=tx.encrypt({InputType::Move,37,-12,400});auto tampered=next;tampered[4]^=1;
|
||||
rejects([&]{rx.decrypt(tampered);},"ciphertext modification rejected");
|
||||
check(rx.decrypt(next)==InputFrame{InputType::Move,37,-12,400},"failed authentication does not expose or advance data");
|
||||
check(rx.decrypt(tx.encrypt(ResetHeldInputRequest))==ResetHeldInputRequest,"the reset request uses the authenticated input frame format");
|
||||
InputCipher wrong(inputSessionKey(secret,b,a,nb,na));rejects([&]{wrong.decrypt(packet);},"reflection across directions rejected");
|
||||
InputCipher otherSession(inputSessionKey(secret,a,b,randomHex(16),nb));rejects([&]{otherSession.decrypt(packet);},"old-session input rejected");
|
||||
WSADATA data{};if(WSAStartup(MAKEWORD(2,2),&data))throw std::runtime_error("WSAStartup");
|
||||
@@ -567,6 +688,6 @@ void channelChecks()
|
||||
}
|
||||
int main()
|
||||
{
|
||||
try{channelChecks();hubChecks();offlineDiscoveryChecks();fallbackChecks();datagramChecks();routerChecks();meshChecks();std::cout<<"Passed "<<passed<<" LAN input checks\n";}
|
||||
try{channelChecks();hubChecks();offlineDiscoveryChecks();fallbackChecks();datagramChecks();routerChecks();meshChecks();handoffBlockChecks();heldInputReleaseChecks();pairedInputResetChecks();std::cout<<"Passed "<<passed<<" LAN input checks\n";}
|
||||
catch(const std::exception &e){std::cerr<<"FAIL: "<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -884,6 +884,8 @@ int main(int argc, char **argv)
|
||||
{L"New editor", L"Ctrl+Alt+F10", L"C:\\Apps\\Editor.exe", false, true},
|
||||
{L"Insert note", L"Ctrl+Alt+F11", L"C:\\Apps\\Editor.exe", true, false,
|
||||
ks::CustomShortcutAction::SendText, L"Edit", L"First line\r\nSecond line", 101},
|
||||
{L"Open board", L"Ctrl+Alt+F12", L"", true, false, ks::CustomShortcutAction::OpenUrl,
|
||||
L"", L"", 0, L"https://example.com/board", ks::ShortcutBrowser::Chrome, L"Profile 1"},
|
||||
};
|
||||
require(ks::decodeSettings(ks::encodeSettings(custom), {}).customShortcuts == custom.customShortcuts,
|
||||
"custom shortcut actions, launch modes, text and enabled state roundtrip");
|
||||
@@ -891,6 +893,18 @@ int main(int argc, char **argv)
|
||||
rejects([&] { ks::validateSettings(custom); }, "custom shortcuts cannot shadow built-in shortcuts");
|
||||
custom.customShortcuts[0].enabled = false;
|
||||
ks::validateSettings(custom);
|
||||
auto &web = custom.customShortcuts.back();
|
||||
web.url = L"file:///C:/Windows/notepad.exe";
|
||||
rejects([&] { ks::validateSettings(custom); }, "URL shortcut requires HTTP or HTTPS");
|
||||
web.url = L"https://example.com/a%20b?q=one%20two#result";
|
||||
web.chromeProfile = L"..\\Other";
|
||||
rejects([&] { ks::validateSettings(custom); }, "Chrome profile must be a single directory name");
|
||||
web.chromeProfile.clear();
|
||||
web.browser = ks::ShortcutBrowser::Other;
|
||||
rejects([&] { ks::validateSettings(custom); }, "specific browser requires an executable");
|
||||
web.executable = L"C:\\Apps\\Browser.exe";
|
||||
require(ks::decodeSettings(ks::encodeSettings(custom), {}).customShortcuts == custom.customShortcuts,
|
||||
"URL shortcut and specific browser roundtrip");
|
||||
custom.customShortcuts[2].controlClass.clear();
|
||||
rejects([&] { ks::validateSettings(custom); }, "text shortcuts require a target control");
|
||||
require(ks::loadSettings(temp / L"defaults.json", {}).screenshot == L"Win+Shift+S",
|
||||
|
||||