[gtksourceview/wip/chergert/gsv-gtk4: 79/117] completion: use gdk_surface_move_to_rect()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 79/117] completion: use gdk_surface_move_to_rect()
- Date: Wed, 29 Jan 2020 17:34:02 +0000 (UTC)
commit 63709eaec8ef8a3d1fac999f76629f7526dea824
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 15 14:11:55 2020 -0800
completion: use gdk_surface_move_to_rect()
This avoids manual control over placement and instead relies on the
window manager (or GDK on X11) to place the window in an appropriate
place using relative gravity of windows.
gtksourceview/gtksourcecompletion.c | 56 ++++++++++++++-----------------------
1 file changed, 21 insertions(+), 35 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index cef4aa90..3c8f2ddc 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -738,34 +738,34 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
static void
update_info_position (GtkSourceCompletion *completion)
{
- GdkDisplay *display;
- GdkMonitor *monitor;
- GdkWindow *window;
+ GdkSurface *main_surface;
+ GdkSurface *info_surface;
GdkRectangle geom;
- gint x, y;
- gint width, height;
- gint info_width;
- gtk_window_get_position (GTK_WINDOW (completion->main_window), &x, &y);
- gtk_window_get_size (GTK_WINDOW (completion->main_window), &width, &height);
- gtk_window_get_size (GTK_WINDOW (completion->info_window), &info_width, NULL);
-
- display = gtk_widget_get_display (GTK_WIDGET (completion->main_window));
- window = gtk_widget_get_window (GTK_WIDGET (completion->main_window));
- monitor = gdk_display_get_monitor_at_window (display, window);
- gdk_monitor_get_geometry (monitor, &geom);
-
- /* Determine on which side to place it */
- if (x + width + info_width >= geom.width)
+ if (!GTK_IS_NATIVE (completion->main_window) ||
+ !GTK_IS_NATIVE (completion->info_window))
{
- x -= info_width;
+ return;
}
- else
+
+ main_surface = gtk_native_get_surface (GTK_NATIVE (completion->main_window));
+ info_surface = gtk_native_get_surface (GTK_NATIVE (completion->info_window));
+
+ if (main_surface == NULL || info_surface == NULL)
{
- x += width;
+ return;
}
- gtk_window_move (GTK_WINDOW (completion->info_window), x, y);
+ gdk_surface_get_position (main_surface, &geom.x, &geom.y);
+ geom.width = gdk_surface_get_width (main_surface);
+ geom.height = gdk_surface_get_height (main_surface);
+
+ gdk_surface_move_to_rect (info_surface,
+ &geom,
+ GDK_GRAVITY_NORTH_EAST,
+ GDK_GRAVITY_NORTH_WEST,
+ GDK_ANCHOR_FLIP_X,
+ 0, 0);
}
static GtkSourceCompletionProvider *
@@ -1261,15 +1261,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)
{
@@ -2182,11 +2173,6 @@ init_main_window (GtkSourceCompletion *completion,
gtk_window_set_attached_to (GTK_WINDOW (completion->main_window),
GTK_WIDGET (completion->view));
- g_signal_connect (completion->main_window,
- "configure-event",
- G_CALLBACK (gtk_source_completion_configure_event),
- completion);
-
g_signal_connect_swapped (completion->main_window,
"size-allocate",
G_CALLBACK (update_window_position),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]