Skip to content

Commit

Permalink
Fix copy to clipboard (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 authored Oct 10, 2024
1 parent 08305c3 commit 2aeadad
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/SaveDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ public class Screenshot.SaveDialog : Granite.Dialog {
});

clipboard_btn.clicked.connect (() => {
Gdk.Display.get_default ().get_clipboard ().set_texture (Gdk.Texture.for_pixbuf (pixbuf));
close ();
Gdk.Clipboard clipboard = Gdk.Display.get_default ().get_clipboard ();
clipboard.changed.connect (on_clipboard_changed);
clipboard.set_texture (Gdk.Texture.for_pixbuf (pixbuf));
});

retry_btn.clicked.connect (() => {
Expand Down Expand Up @@ -249,4 +250,25 @@ public class Screenshot.SaveDialog : Granite.Dialog {
folder_image.gicon = new ThemedIcon ("folder");
}
}

private void on_clipboard_changed () {
Gdk.Clipboard clipboard = Gdk.Display.get_default ().get_clipboard ();
Gdk.Texture texture = Gdk.Texture.for_pixbuf (pixbuf);
clipboard.read_texture_async.begin (null, (obj, res) => {
Gdk.Texture _texture = clipboard.read_texture_async.end (res);
if (_texture != null && _texture.height == texture.height && _texture.width == texture.width) {
hide_destroy ();
}
});
}

public void hide_destroy () {
hide ();

// Timeout added to ensure the clipboard is synced
// before closing the window
GLib.Timeout.add_once (500, () => {
close ();
});
}
}

0 comments on commit 2aeadad

Please sign in to comment.