1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <ctk/ctk.h>

static gboolean
draw_popup (CtkWidget *widget,
            cairo_t   *cr,
            gpointer   data)
{
  cairo_set_source_rgb (cr, 1, 0, 0);
  cairo_paint (cr);

  return FALSE;
}

static gboolean
place_popup (CtkWidget *parent,
             CdkEvent  *event,
             CtkWidget *popup)
{
  CdkEventMotion *ev_motion = (CdkEventMotion *) event;<--- Variable 'ev_motion' can be declared as pointer to const
  gint width, height;

  ctk_window_get_size (CTK_WINDOW (popup), &width, &height);
  ctk_window_move (CTK_WINDOW (popup),
                   (int) ev_motion->x_root - width / 2,
                   (int) ev_motion->y_root - height / 2);

  return FALSE;
}

static gboolean
on_map_event (CtkWidget *parent,
              CdkEvent  *event,
              gpointer   data)
{
  CtkWidget *popup;

  popup = ctk_window_new (CTK_WINDOW_POPUP);

  ctk_widget_set_size_request (CTK_WIDGET (popup), 20, 20);
  ctk_widget_set_app_paintable (CTK_WIDGET (popup), TRUE);
  ctk_window_set_transient_for (CTK_WINDOW (popup), CTK_WINDOW (parent));
  g_signal_connect (popup, "draw", G_CALLBACK (draw_popup), NULL);
  g_signal_connect (parent, "motion-notify-event", G_CALLBACK (place_popup), popup);

  ctk_widget_show (popup);

  return FALSE;
}

int
main (int argc, char *argv[])
{
  CtkWidget *window;

  ctk_init (&argc, &argv);

  window = ctk_window_new (CTK_WINDOW_TOPLEVEL);

  ctk_widget_set_events (window, CDK_POINTER_MOTION_MASK);
  g_signal_connect (window, "destroy", ctk_main_quit, NULL);
  g_signal_connect (window, "map-event", G_CALLBACK (on_map_event), NULL);

  ctk_widget_show (window);

  ctk_main ();

  return 0;
}