[fractal] media-viewer: disconnect the keypress signal on unmap



commit 4af4ff40734823575cb30ac3cba695e631fd37a7
Author: Daniel GarcĂ­a Moreno <danigm wadobo com>
Date:   Tue Dec 18 12:27:53 2018 +0100

    media-viewer: disconnect the keypress signal on unmap
    
    We were storing the signal_id, but we never disconnect that handler so
    it worked the first time and then we were getting all key events and
    future widgets creation doesn't work.
    
    This patch disconnect the signal just when the widget gets unmapped, as
    we create a new widget when we open the media-viewer again.
    
    Fix #402

 fractal-gtk/src/widgets/media_viewer.rs | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/media_viewer.rs b/fractal-gtk/src/widgets/media_viewer.rs
index 0945794..1525021 100644
--- a/fractal-gtk/src/widgets/media_viewer.rs
+++ b/fractal-gtk/src/widgets/media_viewer.rs
@@ -625,18 +625,6 @@ impl MediaViewer {
         next_media_button.connect_clicked(move |_| {
             own.borrow_mut().next_media();
         });
-        let back = self
-            .builder
-            .get_object::<gtk::Button>("media_viewer_back_button")
-            .expect("Can't find media_viewer_back_button in ui file.");
-        let previous_media_button = self
-            .builder
-            .get_object::<gtk::Button>("previous_media_button")
-            .expect("Cant find previous_media_button in ui file.");
-        let next_media_button = self
-            .builder
-            .get_object::<gtk::Button>("next_media_button")
-            .expect("Cant find next_media_button in ui file.");
         let full_screen_button = self
             .builder
             .get_object::<gtk::Button>("full_screen_button")
@@ -657,8 +645,7 @@ impl MediaViewer {
                             }
                         }
 
-                        back.clicked();
-                        Inhibit(true)
+                        Inhibit(false)
                     }
                     gdk::enums::key::Left => {
                         previous_media_button.clicked();
@@ -672,6 +659,16 @@ impl MediaViewer {
                 }
             });
         self.data.borrow_mut().signal_id = Some(id);
+
+        // Remove the keyboard signal management on hide
+        let data = self.data.clone();
+        media_viewer_box.connect_unmap(move |_| {
+            let id = data.borrow_mut().signal_id.take();
+            let main_window = &data.borrow().main_window;
+            if let Some(id) = id {
+                signal::signal_handler_disconnect(main_window, id);
+            }
+        });
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]