Skip to content

Commit

Permalink
Add a basic screen capture implementation for Windows
Browse files Browse the repository at this point in the history
This launches the snipping utility to populate the clipboard, but we don't currently have a way to detect when this is finished to automatically create a new document.
Still, this is better than failing completely.
  • Loading branch information
cameronwhite committed Dec 25, 2024
1 parent d030197 commit 6d15a24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Pinta/ActionHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ActionHandlers ()
{
// File
new NewDocumentAction (actions, chrome, palette, settings, workspace),
new NewScreenshotAction (chrome, workspace, actions),
new NewScreenshotAction (system, chrome, workspace, actions),
new OpenDocumentAction (actions.File, chrome, workspace, recentFiles, imageFormats),
new SaveDocumentAction (actions.File, workspace),
new SaveDocumentAsAction (actions.File, workspace),
Expand Down
17 changes: 16 additions & 1 deletion Pinta/Actions/File/NewScreenshotAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ namespace Pinta.Actions;

internal sealed class NewScreenshotAction : IActionHandler
{
private readonly SystemManager system;
private readonly ChromeManager chrome;
private readonly WorkspaceManager workspace;
private readonly ActionManager actions;

internal NewScreenshotAction (
SystemManager system,
ChromeManager chrome,
WorkspaceManager workspace,
ActionManager actions)
{
this.system = system;
this.chrome = chrome;
this.workspace = workspace;
this.actions = actions;
Expand All @@ -62,13 +66,14 @@ void IActionHandler.Uninitialize ()
private async void Activated (object sender, EventArgs args)
{
// GTK4 removed gdk_pixbuf_get_from_window(), so we need to use OS-specific APis to take a screenshot.
// TODO-GTK4 - implement screenshots for Windows
try {

if (SystemManager.GetOperatingSystem () == OS.X11)
await HandleX11 ();
else if (SystemManager.GetOperatingSystem () == OS.Mac)
HandleMac ();
else if (SystemManager.GetOperatingSystem () == OS.Windows)
await HandleWindows ();
else
HandleDefault ();

Expand Down Expand Up @@ -169,4 +174,14 @@ await handle.WatchResponseAsync (
}
);
}

private async Task HandleWindows ()
{
// Launch the standard screen capture utility which will add to the clipboard.
// https://learn.microsoft.com/en-us/windows/uwp/launch-resume/launch-screen-snipping#open-a-new-snip-from-your-app
// LaunchUri() returns once the application is launched, not when it's finished, so we don't
// currently have a way to be notified when we can add a new document. Listening for clipboard change
// events could have many false positives.
await system.LaunchUri ("ms-screenclip:");
}
}

0 comments on commit 6d15a24

Please sign in to comment.