Debian Codegraph @

tests/test-xy-stress.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * @file tests/test-xy.c Unit test: X, Y hints
4 *
5 * @Copyright(C) 2005 Christian Hammond <[email protected]>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or(at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 #include <libnotify/notify.h>
24 #include <gtk/gtk.h>
25 #include <stdio.h>
26 #include <unistd.h>
27
28 static void
29 _handle_closed (GObject * obj)
30 {
31 g_message ("closing");
32 g_object_unref (obj);
33 }
34
35 static void
36 emit_notification (int x, int y)
37 {
38 char *buffer;
39 NotifyNotification *n;
40
41 buffer = g_strdup_printf ("This notification should point to %d, %d.",
42 x,
43 y);
44
45 n = notify_notification_new ("X, Y Test", buffer, NULL);
46 g_free (buffer);
47
48 notify_notification_set_hint_int32 (n, "x", x);
49 notify_notification_set_hint_int32 (n, "y", y);
50
51 g_signal_connect (G_OBJECT (n),
52 "closed",
53 G_CALLBACK (_handle_closed),
54 NULL);
55
56 if (!notify_notification_show (n, NULL))
57 fprintf (stderr, "failed to send notification\n");
58 }
59
60 static gboolean
61 _popup_random_bubble (gpointer unused)
62 {
63 GdkDisplay *display;
64 GListModel *monitors;
65 GdkMonitor *monitor;
66 GdkRectangle rect;
67 int x, y;
68
69 display = gdk_display_get_default ();
70 monitors = gdk_display_get_monitors (display);
71 monitor = g_list_model_get_item (monitors, 0);
72 gdk_monitor_get_geometry (monitor, &rect);
73
74 x = g_random_int_range (rect.x, rect.x + rect.width - 1);
75 y = g_random_int_range (rect.y, rect.y + rect.height - 1);
76 emit_notification (x, y);
77
78 return TRUE;
79 }
80
81 int
82 main (int argc, char **argv)
83 {
84 GMainLoop *loop;
85
86 gtk_init ();
87
88 notify_init ("XY");
89
90 g_timeout_add (1000, _popup_random_bubble, NULL);
91
92 loop = g_main_loop_new (NULL, FALSE);
93 g_main_loop_run (loop);
94
95 return 0;
96 }