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