[gnome-flashback/wip/segeiger/gnome-3-18-inputmethods] Positioning for popup window
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback/wip/segeiger/gnome-3-18-inputmethods] Positioning for popup window
- Date: Wed, 13 Jan 2016 12:36:27 +0000 (UTC)
commit d723be60bbb76a225f0873a94a86e1b48ea0a077
Author: Sebastian Geiger <sbastig gmx net>
Date: Wed Jan 13 13:36:12 2016 +0100
Positioning for popup window
.../libinput-sources/gf-candidate-popup.c | 40 ++++++++++++++++++--
1 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-candidate-popup.c
b/gnome-flashback/libinput-sources/gf-candidate-popup.c
index 7bd0735..48cb7a6 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-popup.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-popup.c
@@ -20,13 +20,11 @@
/* _XOPEN_SOURCE macro needed for floor function from math library */
#define _XOPEN_SOURCE 600
-#include "math.h"
+#include <math.h>
#include "gf-candidate-popup.h"
#include "gf-candidate-area.h"
-#include "gtk/gtk.h"
-
struct _GfCandidatePopup
{
GObject parent;
@@ -73,7 +71,41 @@ set_cursor_location_cb (IBusPanelService *service,
gint h,
gpointer user_data)
{
- g_message ("set_cursor_location_cb");
+ GfCandidatePopup *popup;
+ gint height, width;
+ GdkScreen *screen;
+ GdkWindow *window;
+ GdkRectangle rectangle;
+ int monitor;
+
+ /* We want to position the candidate window as close as possible to the
+ * cursor. But we do not want it to extend outside the screen area.
+ * If placing the candidate area below the cursor would cause parts of the
+ * window to extend outside the screen, then we will place it above the
+ * cursor instead. */
+
+ g_message ("set_cursor_location_cb: (x: %d, y: %d, w: %d, h: %d)", x, y, w, h);
+
+ popup = GF_CANDIDATE_POPUP (user_data);
+
+ gtk_window_get_size (GTK_WINDOW (popup->window), &height, &width);
+
+ window = gtk_widget_get_window (popup->window);
+ screen = gdk_window_get_screen (window);
+ monitor = gdk_screen_get_monitor_at_window (screen, window);
+ gdk_screen_get_monitor_geometry (screen, monitor, &rectangle);
+
+ if (x + width > rectangle.width)
+ {
+ x = x - height - h;
+ }
+
+ if (y + height > rectangle.height)
+ {
+ y = y - width - h;
+ }
+
+ gtk_window_move (GTK_WINDOW (popup->window), x, y);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]