2015-12-21 13:35:53 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2016-11-18 06:24:31 +00:00
|
|
|
static void
|
|
|
|
draw_popup (GtkDrawingArea *da,
|
|
|
|
cairo_t *cr,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2015-12-21 13:35:53 +00:00
|
|
|
{
|
|
|
|
cairo_set_source_rgb (cr, 1, 0, 0);
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
place_popup (GtkWidget *parent,
|
|
|
|
GdkEvent *event,
|
|
|
|
GtkWidget *popup)
|
|
|
|
{
|
|
|
|
gint width, height;
|
2017-08-28 23:11:14 +00:00
|
|
|
gdouble x, y;
|
2015-12-21 13:35:53 +00:00
|
|
|
|
2018-01-16 04:15:51 +00:00
|
|
|
if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
|
|
|
|
{
|
|
|
|
gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
|
|
|
|
gdk_event_get_root_coords (event, &x, &y);
|
|
|
|
gtk_window_move (GTK_WINDOW (popup),
|
|
|
|
(int) x - width / 2,
|
|
|
|
(int) y - height / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2015-12-21 13:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2017-12-31 19:19:34 +00:00
|
|
|
on_map (GtkWidget *parent)
|
2015-12-21 13:35:53 +00:00
|
|
|
{
|
2016-11-18 06:24:31 +00:00
|
|
|
GtkWidget *popup, *da;
|
2015-12-21 13:35:53 +00:00
|
|
|
|
|
|
|
popup = gtk_window_new (GTK_WINDOW_POPUP);
|
2016-11-18 06:24:31 +00:00
|
|
|
da = gtk_drawing_area_new ();
|
|
|
|
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), draw_popup, NULL, NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (popup), da);
|
2015-12-21 13:35:53 +00:00
|
|
|
|
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
|
2018-01-16 04:15:51 +00:00
|
|
|
g_signal_connect (parent, "event", G_CALLBACK (place_popup), popup);
|
2015-12-21 13:35:53 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (popup);
|
2015-12-21 13:35:53 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2015-12-21 13:35:53 +00:00
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
|
|
|
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
|
2017-12-31 19:19:34 +00:00
|
|
|
g_signal_connect (window, "map", G_CALLBACK (on_map), NULL);
|
2015-12-21 13:35:53 +00:00
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|