[gtksourceview/wip/fix-completion] Completion: fix the info window placement



commit e947aa84ddbf434de638e07a875987612b9332ea
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jun 12 16:25:24 2013 +0200

    Completion: fix the info window placement
    
    It would have been easier to update the info window position on the
    "configure-event" signal emitted by the main winodw. But the signal
    isn't emitted (I don't know why).
    
    To reproduce the bug (before this commit) with test-completion:
    - type something in the source view, the completion window appears;
    - click on the Details button;
    - type "something ", with a space, so the completion window moves;
    - the info window hasn't moved.

 gtksourceview/gtksourcecompletion.c |   82 ++++++++++++++++------------------
 1 files changed, 39 insertions(+), 43 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 40263ad..6765add 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -426,6 +426,40 @@ replace_current_word (GtkTextBuffer *buffer,
 }
 
 static void
+update_info_position (GtkSourceCompletion *completion)
+{
+       GdkScreen *screen;
+       gint x, y;
+       gint width, height;
+       gint screen_width;
+       gint info_width;
+
+       if (!gtk_widget_get_visible (GTK_WIDGET (completion->priv->info_window)))
+       {
+               return;
+       }
+
+       gtk_window_get_position (GTK_WINDOW (completion->priv->main_window), &x, &y);
+       gtk_window_get_size (GTK_WINDOW (completion->priv->main_window), &width, &height);
+       gtk_window_get_size (GTK_WINDOW (completion->priv->info_window), &info_width, NULL);
+
+       screen = gtk_window_get_screen (GTK_WINDOW (completion->priv->main_window));
+       screen_width = gdk_screen_get_width (screen);
+
+       /* Determine on which side to place it */
+       if (x + width + info_width >= screen_width)
+       {
+               x -= info_width;
+       }
+       else
+       {
+               x += width;
+       }
+
+       gtk_window_move (GTK_WINDOW (completion->priv->info_window), x, y);
+}
+
+static void
 update_window_position (GtkSourceCompletion *completion)
 {
        GtkSourceCompletionProvider *provider;
@@ -458,6 +492,8 @@ update_window_position (GtkSourceCompletion *completion)
        gtk_source_completion_info_move_to_iter (completion->priv->main_window,
                                                 GTK_TEXT_VIEW (completion->priv->view),
                                                 &iter);
+
+       update_info_position (completion);
 }
 
 static void
@@ -543,6 +579,7 @@ update_info_window_visibility (GtkSourceCompletion *completion)
            gtk_toggle_button_get_active (completion->priv->info_button))
        {
                gtk_widget_show (GTK_WIDGET (completion->priv->info_window));
+               update_info_position (completion);
        }
        else
        {
@@ -632,35 +669,6 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
        g_object_unref (proposal);
 }
 
-static void
-update_info_position (GtkSourceCompletion *completion)
-{
-       GdkScreen *screen;
-       gint x, y;
-       gint width, height;
-       gint screen_width;
-       gint info_width;
-
-       gtk_window_get_position (GTK_WINDOW (completion->priv->main_window), &x, &y);
-       gtk_window_get_size (GTK_WINDOW (completion->priv->main_window), &width, &height);
-       gtk_window_get_size (GTK_WINDOW (completion->priv->info_window), &info_width, NULL);
-
-       screen = gtk_window_get_screen (GTK_WINDOW (completion->priv->main_window));
-       screen_width = gdk_screen_get_width (screen);
-
-       /* Determine on which side to place it */
-       if (x + width + info_width >= screen_width)
-       {
-               x -= info_width;
-       }
-       else
-       {
-               x += width;
-       }
-
-       gtk_window_move (GTK_WINDOW (completion->priv->info_window), x, y);
-}
-
 static GtkSourceCompletionProvider *
 get_visible_provider (GtkSourceCompletion *completion)
 {
@@ -1150,15 +1158,6 @@ selection_changed_cb (GtkTreeSelection    *selection,
 }
 
 static gboolean
-gtk_source_completion_configure_event (GtkWidget           *widget,
-                                       GdkEventConfigure   *event,
-                                       GtkSourceCompletion *completion)
-{
-       update_info_position (completion);
-       return FALSE;
-}
-
-static gboolean
 hide_completion_cb (GtkSourceCompletion *completion)
 {
        gtk_source_completion_hide (completion);
@@ -2257,11 +2256,6 @@ init_main_window (GtkSourceCompletion *completion,
                                     WINDOW_WIDTH,
                                     WINDOW_HEIGHT);
 
-       g_signal_connect_after (completion->priv->main_window,
-                               "configure-event",
-                               G_CALLBACK (gtk_source_completion_configure_event),
-                               completion);
-
        g_signal_connect (completion->priv->main_window,
                          "delete-event",
                          G_CALLBACK (gtk_widget_hide_on_delete),
@@ -2672,6 +2666,8 @@ gtk_source_completion_move_window (GtkSourceCompletion *completion,
        gtk_source_completion_info_move_to_iter (completion->priv->main_window,
                                                 GTK_TEXT_VIEW (completion->priv->view),
                                                 iter);
+
+       update_info_position (completion);
 }
 
 /**


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