diff --git a/fractal-gtk/src/app/connect/send.rs b/fractal-gtk/src/app/connect/send.rs index ebe32fbc..e398970f 100644 --- a/fractal-gtk/src/app/connect/send.rs +++ b/fractal-gtk/src/app/connect/send.rs @@ -2,6 +2,7 @@ use gdk; use gtk; use gtk::prelude::*; use sourceview::BufferExt; +use appop::attach; use app::App; @@ -56,7 +57,7 @@ impl App { op = self.op.clone(); msg_entry.connect_paste_clipboard(move |_| { - op.lock().unwrap().paste(); + attach::paste(op.clone()); }); msg_entry.connect_focus_in_event(clone!(msg_entry_box => move |_, _| { diff --git a/fractal-gtk/src/appop/attach.rs b/fractal-gtk/src/appop/attach.rs index d12c6601..cb36a2b1 100644 --- a/fractal-gtk/src/appop/attach.rs +++ b/fractal-gtk/src/appop/attach.rs @@ -1,5 +1,6 @@ use i18n::i18n; +use std::sync::{Arc, Mutex}; use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; @@ -22,24 +23,6 @@ use util::get_pixbuf_data; impl AppOp { - pub fn paste(&self) { - if let Some(display) = gdk::Display::get_default() { - if let Some(clipboard) = gtk::Clipboard::get_default(&display) { - if clipboard.wait_is_image_available() { - if let Some(pixb) = clipboard.wait_for_image() { - self.draw_image_paste_dialog(&pixb); - - // removing text from clipboard - clipboard.set_text(""); - clipboard.set_image(&pixb); - } - } else { - // TODO: manage code pasting - } - } - } - } - fn draw_image_paste_dialog(&self, pixb: &Pixbuf) { let w = pixb.get_width(); let h = pixb.get_height(); @@ -107,3 +90,28 @@ fn store_pixbuf(pixb: &Pixbuf) -> Result { Ok(file) } + +/// This function receives the appop mutex to avoid lock the interface +/// This was previously an appop method that receives &self, but that +/// force us to lock the interface for the entire function that causes +/// problems because we call to wait_is_image_available that makes that +/// tries to continue the loop and that give us to a deadlock so +/// this function minimize the lock and avoid that kind of problems +/// See: https://gitlab.gnome.org/World/fractal/issues/284 +pub fn paste(op: Arc>) { + if let Some(display) = gdk::Display::get_default() { + if let Some(clipboard) = gtk::Clipboard::get_default(&display) { + if clipboard.wait_is_image_available() { + if let Some(pixb) = clipboard.wait_for_image() { + op.lock().unwrap().draw_image_paste_dialog(&pixb); + + // removing text from clipboard + clipboard.set_text(""); + clipboard.set_image(&pixb); + } + } else { + // TODO: manage code pasting + } + } + } +} diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs index b8f1dd0e..36d83cc9 100644 --- a/fractal-gtk/src/appop/mod.rs +++ b/fractal-gtk/src/appop/mod.rs @@ -36,7 +36,7 @@ mod files; mod message; mod directory; mod notify; -mod attach; +pub mod attach; mod member; mod invite; mod about;