Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
211a6bdb33 | ||
|
|
240cc535ba | ||
|
|
92b72c2e7b | ||
|
|
59d01375ff | ||
|
|
2ffee2f880 | ||
|
|
e5987dee22 | ||
|
|
77aa5b7894 |
No files matched your search
+1
-1
@@ -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.12 LANGUAGES C CXX RC)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
|
||||
endif()
|
||||
|
||||
@@ -139,6 +139,13 @@ 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. The hint clears when 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 on the PC named
|
||||
in the hint. 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,17 @@
|
||||
# Latest Windows release
|
||||
|
||||
## 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
|
||||
f21c0f10aeb188f688bf4f3cfec8020d9ffbf92d86f15ad09efbb507dcbe7c49 KSwitcher-win-x64.zip
|
||||
+79
-79
@@ -1,181 +1,181 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"version": "0.8.10",
|
||||
"files": [
|
||||
{
|
||||
"sha256": "51c2b60bd27676ef92c674033e0a7295ab666c95ec19f0514dc6e6af22787c43",
|
||||
"size": 3283456,
|
||||
"path": "KSwitcher.exe"
|
||||
"path": "KSwitcher.exe",
|
||||
"size": 3311104,
|
||||
"sha256": "a5454e72ec1dc0acfebd8ed713b8ca9a124cf501ef7ae7ee28e66a865b3e821f"
|
||||
},
|
||||
{
|
||||
"sha256": "f3f9f375bde4afc5e0099fc6db5187e5d34e7a1bb4f98e27255b29a0aad36240",
|
||||
"size": 2870784,
|
||||
"path": "KSwitcher.Config.exe"
|
||||
"path": "KSwitcher.Config.exe",
|
||||
"size": 2897408,
|
||||
"sha256": "3695f4c1f02fdf9aa27230b22f855685e028c82402c1d05f1198e01c28e023aa"
|
||||
},
|
||||
{
|
||||
"sha256": "bf3c38225db36eb5f73ffb41da7b45094d5c41d08ca74c82dd7612ec563e779d",
|
||||
"size": 3200512,
|
||||
"path": "KSwitcher.Screenshot.exe"
|
||||
"path": "KSwitcher.Screenshot.exe",
|
||||
"size": 3209216,
|
||||
"sha256": "cc0bb2b9bfab49d1c639a97b6ca55aca1bc502f6ca3cc03525f84ff646b7bfd3"
|
||||
},
|
||||
{
|
||||
"sha256": "3303797ea63154f9ec3ef302e792884abdaba87f174811cfcf91e1595bc1bfa6",
|
||||
"size": 6019072,
|
||||
"path": "KSwitcher.Files.exe"
|
||||
"path": "KSwitcher.Files.exe",
|
||||
"size": 6039040,
|
||||
"sha256": "2ccbd71bff0dd09f3f00aa063c33307dcfb7bf94811a9cd5f15213af73499f2a"
|
||||
},
|
||||
{
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6",
|
||||
"path": "WebView2Loader.dll",
|
||||
"size": 194912,
|
||||
"path": "WebView2Loader.dll"
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6"
|
||||
},
|
||||
{
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f",
|
||||
"path": "terminal/addon-fit-LICENSE.txt",
|
||||
"size": 1103,
|
||||
"path": "terminal/addon-fit-LICENSE.txt"
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f"
|
||||
},
|
||||
{
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527",
|
||||
"path": "terminal/addon-fit.js",
|
||||
"size": 1521,
|
||||
"path": "terminal/addon-fit.js"
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527"
|
||||
},
|
||||
{
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef",
|
||||
"path": "terminal/index.html",
|
||||
"size": 527,
|
||||
"path": "terminal/index.html"
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef"
|
||||
},
|
||||
{
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473",
|
||||
"path": "terminal/markdown-it-LICENSE.txt",
|
||||
"size": 1073,
|
||||
"path": "terminal/markdown-it-LICENSE.txt"
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473"
|
||||
},
|
||||
{
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e",
|
||||
"path": "terminal/markdown-it.js",
|
||||
"size": 100786,
|
||||
"path": "terminal/markdown-it.js"
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e"
|
||||
},
|
||||
{
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2",
|
||||
"path": "terminal/markdown.html",
|
||||
"size": 3800,
|
||||
"path": "terminal/markdown.html"
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2"
|
||||
},
|
||||
{
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96",
|
||||
"path": "terminal/markdown.js",
|
||||
"size": 18721,
|
||||
"path": "terminal/markdown.js"
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96"
|
||||
},
|
||||
{
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80",
|
||||
"path": "terminal/mermaid-LICENSE.txt",
|
||||
"size": 1089,
|
||||
"path": "terminal/mermaid-LICENSE.txt"
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80"
|
||||
},
|
||||
{
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3",
|
||||
"path": "terminal/mermaid.js",
|
||||
"size": 5537838,
|
||||
"path": "terminal/mermaid.js"
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3"
|
||||
},
|
||||
{
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7",
|
||||
"path": "terminal/terminal.js",
|
||||
"size": 6627,
|
||||
"path": "terminal/terminal.js"
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7"
|
||||
},
|
||||
{
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd",
|
||||
"path": "terminal/xterm-LICENSE.txt",
|
||||
"size": 1261,
|
||||
"path": "terminal/xterm-LICENSE.txt"
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd"
|
||||
},
|
||||
{
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6",
|
||||
"path": "terminal/xterm.css",
|
||||
"size": 7112,
|
||||
"path": "terminal/xterm.css"
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6"
|
||||
},
|
||||
{
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972",
|
||||
"path": "terminal/xterm.js",
|
||||
"size": 488663,
|
||||
"path": "terminal/xterm.js"
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972"
|
||||
},
|
||||
{
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c",
|
||||
"path": "LICENSE",
|
||||
"size": 4401,
|
||||
"path": "LICENSE"
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c"
|
||||
},
|
||||
{
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831",
|
||||
"path": "json-LICENSE.txt",
|
||||
"size": 1096,
|
||||
"path": "json-LICENSE.txt"
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831"
|
||||
},
|
||||
{
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625",
|
||||
"path": "files-text-license.txt",
|
||||
"size": 883,
|
||||
"path": "files-text-license.txt"
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625"
|
||||
},
|
||||
{
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d",
|
||||
"path": "files-archive-license.txt",
|
||||
"size": 4990,
|
||||
"path": "files-archive-license.txt"
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d"
|
||||
},
|
||||
{
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4",
|
||||
"path": "files-image-license.txt",
|
||||
"size": 3044,
|
||||
"path": "files-image-license.txt"
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4"
|
||||
},
|
||||
{
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594",
|
||||
"path": "files-sftp-license.txt",
|
||||
"size": 2064,
|
||||
"path": "files-sftp-license.txt"
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594"
|
||||
},
|
||||
{
|
||||
"sha256": "a71afa4f0c1bd4d676b5fc261f1e5436752f6a1af3ae77068ad35803d615e9e3",
|
||||
"size": 107765,
|
||||
"path": "README.md"
|
||||
"path": "README.md",
|
||||
"size": 108205,
|
||||
"sha256": "d9a53cb9190dfde2415df54c131b8bd293efbd627014a4e0976cea717ae855ae"
|
||||
},
|
||||
{
|
||||
"sha256": "4eac1f410e6b544aa45756e24f4fdfe9193c6f732410656160be54ab27a0d7e4",
|
||||
"size": 17245,
|
||||
"path": "LAN-PREVIEW.md"
|
||||
"path": "LAN-PREVIEW.md",
|
||||
"size": 17689,
|
||||
"sha256": "d8418e72fe7d78862bc101fe7df6de44a185a49d6001afee1a20bd8d98cffcd5"
|
||||
},
|
||||
{
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9",
|
||||
"path": "dictionaries/en.txt",
|
||||
"size": 732485,
|
||||
"path": "dictionaries/en.txt"
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9"
|
||||
},
|
||||
{
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5",
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
|
||||
"size": 20566,
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt"
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5"
|
||||
},
|
||||
{
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311",
|
||||
"path": "dictionaries/README.md",
|
||||
"size": 2265,
|
||||
"path": "dictionaries/README.md"
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311"
|
||||
},
|
||||
{
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849",
|
||||
"path": "dictionaries/ru.txt",
|
||||
"size": 1109134,
|
||||
"path": "dictionaries/ru.txt"
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849"
|
||||
},
|
||||
{
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408",
|
||||
"path": "dictionaries/sources.json",
|
||||
"size": 1280,
|
||||
"path": "dictionaries/sources.json"
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408"
|
||||
},
|
||||
{
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf",
|
||||
"path": "dictionaries/uk.txt",
|
||||
"size": 940799,
|
||||
"path": "dictionaries/uk.txt"
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf"
|
||||
},
|
||||
{
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a",
|
||||
"path": "tools/README.txt",
|
||||
"size": 993,
|
||||
"path": "tools/README.txt"
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a"
|
||||
},
|
||||
{
|
||||
"sha256": "500c399c5bfdf0ba6ff61986cf9cb25d32394c2d4ff9e3304884d372fbff435d",
|
||||
"path": "tools/StayHere.exe",
|
||||
"size": 133120,
|
||||
"path": "tools/StayHere.exe"
|
||||
"sha256": "ad8fa1e781e817f9b04c5148be484d757913941387ffedd4b73fffeb1d119f6a"
|
||||
},
|
||||
{
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413",
|
||||
"path": "tools/StayHere-README.md",
|
||||
"size": 2796,
|
||||
"path": "tools/StayHere-README.md"
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413"
|
||||
}
|
||||
]
|
||||
],
|
||||
"schema": 1,
|
||||
"version": "0.8.12"
|
||||
}
|
||||
+3
-3
@@ -14,8 +14,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,12,0
|
||||
PRODUCTVERSION 0,8,12,0
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
BEGIN
|
||||
@@ -25,7 +25,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
|
||||
VALUE "ProductName", "KSwitcher"
|
||||
VALUE "FileVersion", "0.8.10"
|
||||
VALUE "FileVersion", "0.8.12"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
+82
-21
@@ -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"
|
||||
@@ -226,6 +227,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;
|
||||
@@ -1147,6 +1149,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 +1158,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 +1170,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 +1273,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();
|
||||
@@ -1257,6 +1301,7 @@ 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();
|
||||
refreshTrayInputBlock();
|
||||
}
|
||||
void App::applySettings(const Settings &requested, const Bytes &supplement)
|
||||
{
|
||||
@@ -2330,6 +2375,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 +2405,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 +3394,15 @@ 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);
|
||||
}
|
||||
|
||||
void App::toggleInputProcessing()
|
||||
{
|
||||
if (inputState == InputState::Pausing) return;
|
||||
@@ -3362,10 +3416,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);
|
||||
@@ -3418,6 +3469,8 @@ void App::trayMenu()
|
||||
AppendMenuW(menu, 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…");
|
||||
AppendMenuW(menu, 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…");
|
||||
@@ -3495,6 +3548,14 @@ void App::trayMenu()
|
||||
case ToggleInputProcessing:
|
||||
toggleInputProcessing();
|
||||
break;
|
||||
case ResetHeldInput:
|
||||
if (lan::resetWindowsHeldInput())
|
||||
{
|
||||
if (lanService) lanService->forgetHeldInput();
|
||||
clearMousePresses();
|
||||
}
|
||||
else report(L"Windows could not release all held keys or mouse buttons.");
|
||||
break;
|
||||
case OpenFiles:
|
||||
dispatch(OpenFiles);
|
||||
break;
|
||||
@@ -3731,6 +3792,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 +3913,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:
|
||||
@@ -4106,7 +4167,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,14 @@ class App
|
||||
bool trayRetryPending{};
|
||||
LanInputConnections trayInput;
|
||||
bool trayInputPulse{};
|
||||
std::wstring trayInputBlock;
|
||||
ULONGLONG nextInputBlockNotice{};
|
||||
bool inputBlockNoticeVisible{};
|
||||
HICON trayBaseIcon(int width, int height) const;
|
||||
bool updateTray(DWORD action);
|
||||
void refreshTrayInput();
|
||||
void refreshTrayInputBlock();
|
||||
void clearMousePresses();
|
||||
uint64_t transformAttempt{}, previousAttemptVersion{};
|
||||
std::atomic<uint64_t> activeTransformAttempt{};
|
||||
ULONGLONG previousAttemptAt{};
|
||||
|
||||
+5
-1
@@ -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
|
||||
|
||||
+36
-4
@@ -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;
|
||||
@@ -282,6 +284,26 @@ struct LanService::Impl
|
||||
router->receive(frame.peer,frame.frame,GetTickCount64(),allowEnter);
|
||||
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 +849,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 +876,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(); }
|
||||
@@ -888,6 +912,14 @@ LanInputConnections LanService::inputConnections()const
|
||||
return {std::min(impl->inputConnectedPeers,paired),std::min(impl->inputOnlinePeers,paired),paired,impl->inputWorkerStopped};
|
||||
}
|
||||
bool LanService::tickInput(bool allowEnter){return impl->tickInput(allowEnter);}
|
||||
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)impl->router->forgetHeldKeys();}
|
||||
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,6 +32,8 @@ class LanService
|
||||
bool inputEnabled() const;
|
||||
void setInputPaused(bool);
|
||||
LanInputConnections inputConnections() const;
|
||||
std::wstring inputBlockText() const;
|
||||
void forgetHeldInput();
|
||||
bool tickInput(bool allowEnter = true);
|
||||
bool keyboard(const KBDLLHOOKSTRUCT &, bool down);
|
||||
bool mouse(UINT, const MSLLHOOKSTRUCT &, bool allowEnter);
|
||||
|
||||
+85
-11
@@ -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);
|
||||
|
||||
+15
-4
@@ -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_;}
|
||||
|
||||
+53
-1
@@ -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,17 @@ 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 cancel(uint64_t now){router.cancel(now);}
|
||||
void tick(std::map<std::string,uint64_t> connections,uint64_t now)
|
||||
{
|
||||
@@ -44,10 +67,38 @@ 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)
|
||||
{
|
||||
if(!ready.contains(peer)||!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 +117,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)
|
||||
|
||||
+120
-7
@@ -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,
|
||||
|
||||
+39
-6
@@ -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";
|
||||
|
||||
+56
@@ -481,6 +481,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.
|
||||
|
||||
+109
-25
@@ -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);
|
||||
|
||||
+1
-1
@@ -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.12";
|
||||
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;
|
||||
}
|
||||
+40
-1
@@ -423,7 +423,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 +491,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()) &&
|
||||
|
||||
+75
-5
@@ -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");
|
||||
}
|
||||
@@ -298,6 +299,75 @@ 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");
|
||||
}
|
||||
uint16_t freePort()
|
||||
{
|
||||
SOCKET s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);if(s==INVALID_SOCKET)throw std::runtime_error("test socket");
|
||||
@@ -567,6 +637,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();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",
|
||||
|
||||
Reference in new issue
Block a user