Release v0.6.0: screenshot notifications with previews and responsive clipboard history
This commit is contained in:
+32
-1
@@ -1,4 +1,5 @@
|
||||
#include "screenshot.h"
|
||||
#include "ocr.h"
|
||||
#include "../resources/resource.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -801,6 +802,20 @@ void edit(HWND w, Capture &c)
|
||||
std::min(LONG(MulDiv(700,GetDpiForWindow(w),96)),work.bottom-work.top-40),SWP_FRAMECHANGED|SWP_SHOWWINDOW);
|
||||
layout(w,c); SetForegroundWindow(w); SetFocus(w);
|
||||
}
|
||||
void finishSelection(HWND w,Capture &c,DWORD (*publish)(HWND,const Clip &)=writeClipboard)
|
||||
{
|
||||
if(!c.app.notify) { edit(w,c); return; }
|
||||
auto r=region(c.start,c.end);
|
||||
if(r.right-r.left<2 || r.bottom-r.top<2) return;
|
||||
Surface cropped(r.right-r.left,r.bottom-r.top);
|
||||
BitBlt(cropped.dc,0,0,cropped.width,cropped.height,c.image->dc,r.left,r.top,SRCCOPY);
|
||||
auto clip=screenshotClip(cropped.dc,cropped.width,cropped.height,{});
|
||||
publish(c.app.window,clip);
|
||||
c.copied=true;
|
||||
ShowWindow(w,SW_HIDE);
|
||||
if(c.app.notify(clip)) DestroyWindow(w);
|
||||
else edit(w,c);
|
||||
}
|
||||
LRESULT CALLBACK captureProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
auto c = reinterpret_cast<Capture *>(GetWindowLongPtrW(w,GWLP_USERDATA));
|
||||
@@ -1100,7 +1115,7 @@ LRESULT CALLBACK captureProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (msg==WM_LBUTTONUP)
|
||||
{
|
||||
c->dragging=false; ReleaseCapture();
|
||||
if (!c->editing) edit(w,*c);
|
||||
if (!c->editing) { finishSelection(w,*c); return 0; }
|
||||
else if(c->part!=MarkPart::None)
|
||||
{
|
||||
if(c->part==MarkPart::Start || c->part==MarkPart::End)
|
||||
@@ -1513,6 +1528,22 @@ Clip screenshotClip(HDC source, int width, int height, const std::vector<Screens
|
||||
memcpy(bytes.data()+sizeof(header),output.pixels,bytes.size()-sizeof(header));
|
||||
return Clip{{{CF_DIB,L"",std::move(bytes)}}};
|
||||
}
|
||||
void showScreenshotEditor(ScreenshotHost &app,const Clip &clip)
|
||||
{
|
||||
auto pixels=decodeImage(clip);
|
||||
auto c=std::make_unique<Capture>(app);
|
||||
c->image=std::make_unique<Surface>(pixels.width,pixels.height);
|
||||
memcpy(c->image->pixels,pixels.bgra.data(),pixels.bgra.size());
|
||||
c->start={0,0}; c->end={(LONG)pixels.width,(LONG)pixels.height}; c->copied=true;
|
||||
WNDCLASSW cls{}; cls.hInstance=app.instance; cls.lpfnWndProc=captureProc; cls.lpszClassName=L"KSwitcher.Capture";
|
||||
cls.style=CS_DBLCLKS; cls.hCursor=LoadCursorW(nullptr,IDC_CROSS);
|
||||
cls.hIcon=LoadIconW(app.instance,MAKEINTRESOURCEW(IDI_KSWITCHER)); RegisterClassW(&cls);
|
||||
auto window=CreateWindowExW(0,cls.lpszClassName,L"KSwitcher Screenshot",WS_POPUP,0,0,1,1,
|
||||
app.window,nullptr,app.instance,c.get());
|
||||
if(!window) throw std::runtime_error("Cannot open screenshot editor");
|
||||
c->owned=true; ++app.windows;
|
||||
auto state=c.release(); edit(window,*state);
|
||||
}
|
||||
void showScreenshot(ScreenshotHost &app)
|
||||
{
|
||||
if (activeCapture) { showRequestedWindow(activeCapture); SetForegroundWindow(activeCapture); return; }
|
||||
|
||||
Reference in New Issue
Block a user