[geary] Work around present() not actually raising windows under Wayland.



commit e333794f616e61a7ee38d79def79455b2ff359ec
Author: Michael James Gratton <mike vee net>
Date:   Wed Feb 7 15:01:34 2018 +1100

    Work around present() not actually raising windows under Wayland.
    
    This uses the method of using present_with_time() with value instead of
    Gdk.CURRENT_TIME as the arg value, as suggested in Bug 766284.
    
    Fixes Bug 776881 under Wayland, maybe also under X11.
    
    * src/client/application/geary-application.vala (GearyApplication),
      src/client/composer/composer-container.vala (ComposerContainer):
      Use workaround in present().
    
    * src/client/application/geary-controller.vala (GearyController),
      src/client/application/secret-mediator.vala (SecretMediator):
      Use GearyApplication.present() instead of calling it directly on the
      main window, as needed.
    
    * src/client/composer/composer-embed.vala (ComposerEmbed): Just use the
      base class's present rather that duplicating the old implementation.

 src/client/application/geary-application.vala |    9 ++++++---
 src/client/application/geary-controller.vala  |   18 ++++++++----------
 src/client/application/secret-mediator.vala   |   21 +++++++++++----------
 src/client/composer/composer-container.vala   |    7 ++++++-
 src/client/composer/composer-embed.vala       |    4 ----
 5 files changed, 31 insertions(+), 28 deletions(-)
---
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index 48f0ea6..d1ef67f 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -222,9 +222,12 @@ public class GearyApplication : Gtk.Application {
         if (controller.main_window == null)
             return false;
 
-        // When the app is started hidden, show_all() never gets
-        // called, do so here to prevent an empty window appearing.
-        controller.main_window.present();
+        // Use present_with_time and a made up time so the present
+        // actually works, as a work around for Bug 766284
+        // <https://bugzilla.gnome.org/show_bug.cgi?id=766284>.
+        this.controller.main_window.present_with_time(
+            (uint32) (get_real_time() / 1000)
+        );
 
         return true;
     }
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index c9d3406..307f178 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1437,13 +1437,11 @@ public class GearyController : Geary.BaseObject {
         if (conversation != null)
             main_window.conversation_list_view.select_conversation(conversation);
     }
-    
+
     private void on_indicator_activated_application(uint32 timestamp) {
-        // When the app is started hidden, show_all() never gets
-        // called, do so here to prevent an empty window appearing.
-        main_window.present_with_time(timestamp);
+        this.application.present();
     }
-    
+
     private void on_indicator_activated_composer(uint32 timestamp) {
         on_indicator_activated_application(timestamp);
         on_new_message(null);
@@ -2286,7 +2284,7 @@ public class GearyController : Geary.BaseObject {
         
         // Find out what to do with the inline composers.
         // TODO: Remove this in favor of automatically saving drafts
-        main_window.present();
+        this.application.present();
         Gee.List<ComposerWidget> composers_to_destroy = new Gee.ArrayList<ComposerWidget>();
         foreach (ComposerWidget cw in composer_widgets) {
             if (cw.state != ComposerWidget.ComposerState.DETACHED)
@@ -2468,17 +2466,17 @@ public class GearyController : Geary.BaseObject {
             && !current_folder.properties.is_local_only && current_account != null
             && (current_folder as Geary.FolderSupport.Move) != null);
     }
-    
+
     public bool confirm_delete(int num_messages) {
-        main_window.present();
+        this.application.present();
         ConfirmationDialog dialog = new ConfirmationDialog(main_window, ngettext(
             "Do you want to permanently delete this message?",
             "Do you want to permanently delete these messages?", num_messages),
             null, _("Delete"), "destructive-action");
-        
+
         return (dialog.run() == Gtk.ResponseType.OK);
     }
-    
+
     private async void archive_or_delete_selection_async(bool archive, bool trash,
         Cancellable? cancellable) throws Error {
         if (!can_switch_conversation_view())
diff --git a/src/client/application/secret-mediator.vala b/src/client/application/secret-mediator.vala
index 5ed538c..57215d5 100644
--- a/src/client/application/secret-mediator.vala
+++ b/src/client/application/secret-mediator.vala
@@ -115,18 +115,19 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
         // to serialize the code
         int token = yield dialog_mutex.claim_async(null);
 
-        // If the main window is hidden, make it visible now and present to user as transient parent
-        Gtk.Window? main_window = this.instance.get_active_window();
-        if (main_window != null && !main_window.visible) {
-            main_window.present_with_time(Gdk.CURRENT_TIME);
-        }
-
-        PasswordDialog password_dialog = new PasswordDialog(main_window, services.has_smtp(),
-            account_information, services);
+        // Ensure main window present to the window
+        this.instance.present();
+
+        PasswordDialog password_dialog = new PasswordDialog(
+            this.instance.get_active_window(),
+            services.has_smtp(),
+            account_information,
+            services
+        );
         bool result = password_dialog.run();
-        
+
         dialog_mutex.release(ref token);
-        
+
         if (!result) {
             // user cancelled the dialog
             imap_password = null;
diff --git a/src/client/composer/composer-container.vala b/src/client/composer/composer-container.vala
index ba831e6..6a1edf6 100644
--- a/src/client/composer/composer-container.vala
+++ b/src/client/composer/composer-container.vala
@@ -19,7 +19,12 @@ public interface ComposerContainer {
     public abstract Gtk.ApplicationWindow top_window { get; }
 
     public virtual void present() {
-        this.top_window.present();
+        // Use present_with_time and a made up time so the present
+        // actually works, as a work around for Bug 766284
+        // <https://bugzilla.gnome.org/show_bug.cgi?id=766284>.
+        this.top_window.present_with_time(
+            (uint32) (get_real_time() / 1000)
+        );
     }
 
     public virtual unowned Gtk.Widget get_focus() {
diff --git a/src/client/composer/composer-embed.vala b/src/client/composer/composer-embed.vala
index 37d67bc..460e164 100644
--- a/src/client/composer/composer-embed.vala
+++ b/src/client/composer/composer-embed.vala
@@ -186,10 +186,6 @@ public class ComposerEmbed : Gtk.EventBox, ComposerContainer {
         return ret;
     }
 
-    public void present() {
-        top_window.present();
-    }
-
     public void vanish() {
         hide();
         this.composer.state = ComposerWidget.ComposerState.DETACHED;


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