Skip to content

Commit

Permalink
feat: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Oct 8, 2024
1 parent c9718d0 commit 712c10f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/SaveDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,8 @@ public class Screenshot.SaveDialog : Granite.Dialog {

clipboard_btn.clicked.connect (() => {
Gdk.Clipboard clipboard = Gdk.Display.get_default ().get_clipboard ();
Gdk.Texture texture = Gdk.Texture.for_pixbuf (pixbuf);

clipboard.changed.connect (() => {
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 ();
}
});
});

clipboard.set_texture (texture);
clipboard.changed.connect (on_clipboard_changed);
clipboard.set_texture (Gdk.Texture.for_pixbuf (pixbuf));
});

retry_btn.clicked.connect (() => {
Expand Down Expand Up @@ -261,8 +251,22 @@ public class Screenshot.SaveDialog : Granite.Dialog {
}
}

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 ();
});
Expand Down

0 comments on commit 712c10f

Please sign in to comment.