Release v0.6.57: multi-PC input, shared clipboard and resilient Settings Save
This commit is contained in:
1 parent
82292c8a7e
commit
5de010ee44
39 files changed
+1707
-312
No files matched your search
+92
-11
@@ -1,3 +1,4 @@
|
||||
#include "lan_layout.h"
|
||||
#include "../resources/resource.h"
|
||||
#include "app.h"
|
||||
#include "history_preview.h"
|
||||
@@ -520,11 +521,13 @@ void search(HWND w, HistoryView *v)
|
||||
v->pending.clear();
|
||||
auto *app = v->app;
|
||||
app->enqueueHistorySearch(
|
||||
[w, app, q, generation, pinnedOnly]
|
||||
[w, app, q, generation, pinnedOnly, computers=app->historyComputers]
|
||||
{
|
||||
try
|
||||
{
|
||||
auto result = new SearchResult{generation, app->history->search(q, pinnedOnly)};
|
||||
if(!computers.empty())std::erase_if(result->items,[&](const Entry &e){return
|
||||
std::find(computers.begin(),computers.end(),e.computer)==computers.end();});
|
||||
if (!PostMessageW(w, ResultsMessage, 0, (LPARAM)result))
|
||||
delete result;
|
||||
}
|
||||
@@ -534,6 +537,79 @@ void search(HWND w, HistoryView *v)
|
||||
}
|
||||
});
|
||||
}
|
||||
struct ComputerFilter
|
||||
{
|
||||
HWND owner{},list{};HistoryView *view{};bool filling{};
|
||||
std::vector<std::pair<std::string,std::wstring>> computers;
|
||||
};
|
||||
LRESULT CALLBACK filterKeys(HWND w,UINT msg,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR)
|
||||
{
|
||||
if(msg==WM_KEYDOWN&&wp==VK_ESCAPE){DestroyWindow(GetParent(w));return 0;}
|
||||
if(msg==WM_NCDESTROY)RemoveWindowSubclass(w,filterKeys,1);
|
||||
return DefSubclassProc(w,msg,wp,lp);
|
||||
}
|
||||
LRESULT CALLBACK computerFilterProc(HWND w,UINT msg,WPARAM wp,LPARAM lp)
|
||||
{
|
||||
auto *f=reinterpret_cast<ComputerFilter*>(GetWindowLongPtrW(w,GWLP_USERDATA));
|
||||
if(msg==WM_NCCREATE){f=static_cast<ComputerFilter*>(reinterpret_cast<CREATESTRUCTW*>(lp)->lpCreateParams);SetWindowLongPtrW(w,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(f));}
|
||||
if(f&&msg==WM_NOTIFY&&!f->filling&&reinterpret_cast<NMHDR*>(lp)->code==LVN_ITEMCHANGED){
|
||||
auto *change=reinterpret_cast<NMLISTVIEW*>(lp);
|
||||
if(change->iItem>=0&&(change->uChanged&LVIF_STATE)&&((change->uOldState^change->uNewState)&LVIS_STATEIMAGEMASK)){
|
||||
f->filling=true;
|
||||
bool checked=ListView_GetCheckState(f->list,change->iItem)!=0;
|
||||
if(change->iItem==0)for(int i=1;i<=int(f->computers.size());++i)ListView_SetCheckState(f->list,i,checked);
|
||||
bool all=true;auto &chosen=f->view->app->historyComputers;chosen.clear();
|
||||
for(int i=0;i<int(f->computers.size());++i){if(ListView_GetCheckState(f->list,i+1))chosen.push_back(f->computers[i].first);else all=false;}
|
||||
ListView_SetCheckState(f->list,0,all);
|
||||
if(all)chosen.clear();else if(chosen.empty())chosen.push_back("__none");
|
||||
f->filling=false;
|
||||
SetDlgItemTextW(f->owner,118,all?L" Computers: All ▾":L" Computers: Selected ▾");
|
||||
search(f->owner,f->view);
|
||||
f->view->app->saveHistoryView(f->view->rememberedSelection,f->view->rememberedTop,value(f->owner,101),SendDlgItemMessageW(f->owner,117,BM_GETCHECK,0,0)==BST_CHECKED);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if(msg==WM_ACTIVATE&&LOWORD(wp)==WA_INACTIVE){DestroyWindow(w);return 0;}
|
||||
if(msg==WM_CLOSE){DestroyWindow(w);return 0;}
|
||||
if(msg==WM_NCDESTROY){SetWindowLongPtrW(w,GWLP_USERDATA,0);delete f;}
|
||||
return DefWindowProcW(w,msg,wp,lp);
|
||||
}
|
||||
void showComputerFilter(HWND owner,HistoryView *v)
|
||||
{
|
||||
std::map<std::string,std::wstring> names{{"",L"This computer"}};
|
||||
for(auto &entry:v->app->history->entries())if(!entry.computer.empty())names[entry.computer]=entry.computerName;
|
||||
try{
|
||||
auto path=v->app->data/L"lan-pairing.bin";
|
||||
if(std::filesystem::exists(path)){
|
||||
auto config=nlohmann::json::parse(unprotect(readFile(path,256*1024)));
|
||||
for(auto &[id,peer]:config.at("trusted").items())names[id]=wide(peer.at("name").get<std::string>());
|
||||
}
|
||||
}catch(...){}
|
||||
auto *f=new ComputerFilter{owner,nullptr,v,true,{}};
|
||||
for(auto &[id,name]:names)f->computers.push_back({id,name});
|
||||
WNDCLASSW cls{};cls.lpfnWndProc=computerFilterProc;cls.hInstance=v->app->instance;cls.hCursor=LoadCursorW(nullptr,IDC_ARROW);cls.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);cls.lpszClassName=L"KSwitcher.ComputerFilter";RegisterClassW(&cls);
|
||||
RECT r{};GetWindowRect(GetDlgItem(owner,118),&r);
|
||||
int width=scale(owner,300),height=scale(owner,std::min(280,32+int(names.size()+1)*26));
|
||||
MONITORINFO monitor{sizeof(monitor)};GetMonitorInfoW(MonitorFromWindow(owner,MONITOR_DEFAULTTONEAREST),&monitor);
|
||||
int x=std::clamp(int(r.left),int(monitor.rcWork.left),std::max(int(monitor.rcWork.left),int(monitor.rcWork.right)-width));
|
||||
int y=r.bottom+height>monitor.rcWork.bottom?std::max(int(monitor.rcWork.top),int(r.top)-height):int(r.bottom);
|
||||
auto popup=CreateWindowExW(WS_EX_TOOLWINDOW,cls.lpszClassName,L"Computers",WS_POPUP|WS_BORDER,x,y,width,height,owner,nullptr,v->app->instance,f);
|
||||
if(!popup){delete f;return;}
|
||||
RECT client{};GetClientRect(popup,&client);
|
||||
f->list=CreateWindowExW(0,WC_LISTVIEWW,L"Computers",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LVS_REPORT|LVS_NOCOLUMNHEADER|LVS_SINGLESEL,0,0,client.right,client.bottom,popup,nullptr,v->app->instance,nullptr);
|
||||
SendMessageW(f->list,WM_SETFONT,SendDlgItemMessageW(owner,118,WM_GETFONT,0,0),TRUE);
|
||||
ListView_SetExtendedListViewStyle(f->list,LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER);
|
||||
LVCOLUMNW column{LVCF_WIDTH};column.cx=client.right-scale(owner,24);ListView_InsertColumn(f->list,0,&column);
|
||||
auto &chosen=v->app->historyComputers;
|
||||
for(int i=0;i<=int(f->computers.size());++i){
|
||||
std::wstring label=i?f->computers[i-1].second:L"All computers";
|
||||
LVITEMW item{LVIF_TEXT};item.iItem=i;item.pszText=label.data();ListView_InsertItem(f->list,&item);
|
||||
bool checked=chosen.empty()||(i&&std::find(chosen.begin(),chosen.end(),f->computers[i-1].first)!=chosen.end());
|
||||
ListView_SetCheckState(f->list,i,checked);
|
||||
}
|
||||
f->filling=false;SetWindowSubclass(f->list,filterKeys,1,0);
|
||||
ShowWindow(popup,SW_SHOW);SetFocus(f->list);
|
||||
}
|
||||
void requestPreview(HWND w, HistoryView *v, const Entry &entry)
|
||||
{
|
||||
if(v->scrolling) return;
|
||||
@@ -659,7 +735,7 @@ void drawHistoryRow(HWND w, HistoryView *v, const DRAWITEMSTRUCT &draw)
|
||||
DrawTextW(dc, text.c_str(), -1, &title, DT_WORDBREAK | DT_END_ELLIPSIS | DT_NOPREFIX);
|
||||
RECT detail{title.left, box.bottom - scale(w, 26), title.right, box.bottom - scale(w, 8)};
|
||||
SetTextColor(dc, GetSysColor(selected ? COLOR_HIGHLIGHTTEXT : COLOR_GRAYTEXT));
|
||||
auto subtitle = (entry.pinned ? L"★ " : L"") + std::to_wstring(draw.itemID + 1) + L" · " + entry.app;
|
||||
auto subtitle = (entry.pinned ? L"★ " : L"") + std::to_wstring(draw.itemID + 1) + L" · " + entry.app + L" · " + (entry.computer.empty()?L"This computer":entry.computerName);
|
||||
DrawTextW(dc, subtitle.c_str(), -1, &detail, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX);
|
||||
if (draw.itemState & ODS_FOCUS)
|
||||
{
|
||||
@@ -741,6 +817,7 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int id = LOWORD(wp);
|
||||
if(id==118&&HIWORD(wp)==BN_CLICKED){showComputerFilter(w,v);return 0;}
|
||||
if (id == 117 && HIWORD(wp) == BN_CLICKED)
|
||||
{
|
||||
KillTimer(w, 1);
|
||||
@@ -1968,8 +2045,11 @@ void showHistory(App &app, bool visible)
|
||||
auto filter = control(w, L"BUTTON", L"★ Pinned only", WS_TABSTOP | BS_AUTOCHECKBOX,
|
||||
117, 16, 38, 112, 25);
|
||||
SendMessageW(filter, BM_SETCHECK, app.historyPinnedOnly ? BST_CHECKED : BST_UNCHECKED, 0);
|
||||
label(w, L"&Search clipboard history", 136, 12, 500);
|
||||
edit(w, 101, 136, 38, 608);
|
||||
auto computers = control(w,L"BUTTON",app.historyComputers.empty()?L" Computers: All ▾":L" Computers: Selected ▾",
|
||||
WS_TABSTOP | BS_PUSHBUTTON | BS_LEFT,118,136,36,180,28);
|
||||
(void)computers;
|
||||
label(w, L"&Search clipboard history", 328, 12, 400);
|
||||
edit(w, 101, 328, 38, 416);
|
||||
auto list = control(w, L"LISTBOX", L"",
|
||||
WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_BORDER |
|
||||
LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
|
||||
@@ -2098,14 +2178,15 @@ void showSettings(App &app, bool visible)
|
||||
label(w, L"Additional tools and preferences", 24, 76, 660);
|
||||
button(w, L"S&nippets...", 252, 24, 116, 210);
|
||||
label(w, L"Manage reusable text and expansion triggers.", 254, 120, 430);
|
||||
button(w, L"OCR op&tions...", 257, 24, 180, 210);
|
||||
label(w, L"Configure text recognition from images.", 254, 184, 430);
|
||||
button(w, L"S&ync...", 258, 24, 244, 210);
|
||||
label(w, L"Synchronize preferences between computers.", 254, 248, 430);
|
||||
button(w, L"View l&og...", 256, 24, 308, 210);
|
||||
label(w, L"Inspect recent operations and diagnostics.", 254, 312, 430);
|
||||
button(w, L"OCR op&tions...", 257, 24, 170, 210);
|
||||
label(w, L"Configure text recognition from images.", 254, 174, 430);
|
||||
button(w, L"S&ync...", 258, 24, 224, 210);
|
||||
label(w, L"Synchronize preferences between computers.", 254, 228, 430);
|
||||
button(w, L"KSwitcher &computers...", 262, 24, 278, 210);
|
||||
label(w, L"Share mouse and keyboard with paired computers.", 254, 282, 430);
|
||||
button(w, L"View l&og...", 256, 24, 332, 210);
|
||||
label(w, L"Inspect recent operations and diagnostics.", 254, 336, 430);
|
||||
checkbox(w, L"Write lo&g", 208, 24, 378, 210);
|
||||
button(w, L"KSwitcher &computers...", 262, 254, 374, 260);
|
||||
page();
|
||||
|
||||
control(w, L"STATIC", L"No unsaved changes.", 0, 261, 18, 430, 684, 24);
|
||||
|
||||
Reference in new issue
Block a user