summaryrefslogtreecommitdiff
path: root/test/login-helper-server-test.c
blob: 61446e287c9c8d5e2743c25b8ea79094ff0485df (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <libbonobo.h>
#include <login-helper/login-helper.h>
#include <gtk/gtkwindow.h>
#include <gdk/gdkx.h>
#include <X11/Xatom.h>

static void test_init_login_helper_vpointers (LoginHelper *helper, 
					      gpointer test_set_safe, 
					      gpointer test_get_device_reqs, 
					      gpointer test_get_raise_windows);

static gboolean test_set_safe (LoginHelper *helper, gboolean safe);

static LoginHelperDeviceReqFlags test_get_device_reqs (LoginHelper *helper);

static Window* test_get_raise_windows (LoginHelper *helper);

static void    test_post_window (void);

static void    test_set_wm_dock (void);

static GtkWidget *mainwin = NULL;

int
main (int argc, char **argv)
{
	int          ret;
	char        *obj_id, *display_name;
	BonoboObject *helper;
	
	if (!bonobo_init (&argc, argv))
	{
		g_error ("Could not initialize oaf / Bonobo");
	}
	
	obj_id = "OAFIID:GNOME_TEST:1.0";  /* just for testing, install manually */
	
	helper = BONOBO_OBJECT (g_object_new (LOGIN_HELPER_TYPE, NULL));
	
	ret = bonobo_activation_register_active_server (
		obj_id,
		bonobo_object_corba_objref (bonobo_object (helper)),
		NULL);
	
	if (ret != Bonobo_ACTIVATION_REG_SUCCESS)
	{
		switch (ret) 
		{
		case Bonobo_ACTIVATION_REG_NOT_LISTED:
			fprintf (stderr, "OAFIID not listed\n");
			break;
		default:
			fprintf (stderr, "Registration Error: %d\n", ret);
			break;
		}
	}
	else
	{
		CORBA_Environment ev;
		Bonobo_Unknown ret;
		CORBA_exception_init (&ev);
		
		ret = Bonobo_Unknown_queryInterface (
			BONOBO_OBJREF (helper),
			"IDL:Accessibility/LoginHelper:1.0", 
			&ev);
		
		if (BONOBO_EX (&ev))
		{
			fprintf (stderr, "queryInterface error: %s\n", 
				 bonobo_exception_get_text (&ev));
		}
		else
		{
			fprintf (stderr, "query returned %p: objref self = %p\n", 
				 ret, BONOBO_OBJREF (helper));
		}
	}

	/* this is a testing hack - we are changing the LoginHelperClass's vpointers here */
	
	test_init_login_helper_vpointers ((LoginHelper*)helper, test_set_safe, test_get_device_reqs, test_get_raise_windows);

	gtk_init (&argc, &argv);

	test_post_window ();

	bonobo_main ();

	return 0;
}

static void
test_init_login_helper_vpointers (LoginHelper *helper, 
				  gpointer set_safe_func, 
				  gpointer get_device_reqs_func, 
				  gpointer get_raise_windows_func)
{
	LoginHelperClass *klass = LOGIN_HELPER_GET_CLASS (helper);
	klass->set_safe = set_safe_func;
	klass->get_device_reqs = get_device_reqs_func;
	klass->get_raise_windows = get_raise_windows_func;
}

static gboolean
test_set_safe (LoginHelper *helper, gboolean safe)
{
	return TRUE;
}

static LoginHelperDeviceReqFlags
test_get_device_reqs (LoginHelper *helper)
{
	return LOGIN_HELPER_POST_WINDOWS;
}

static Window*
test_get_raise_windows (LoginHelper *helper)
{
        Window *winlist = g_new0 (Window, 2);
	winlist[0] = GDK_WINDOW_XWINDOW (mainwin->window);
	winlist[1] = None;
        return winlist;
}


void
test_set_wm_dock ()
{
  Atom atom_type[1], atom_window_type;

  gtk_widget_hide (mainwin);

  gdk_error_trap_push ();
  atom_window_type = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE");

  atom_type[0] = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_DOCK");

  XChangeProperty (GDK_WINDOW_XDISPLAY (mainwin->window), 
		   GDK_WINDOW_XWINDOW (mainwin->window), 
		   atom_window_type,
		   XA_ATOM, 32, PropModeReplace,
		   (guchar *) &atom_type, 1);
  gdk_error_trap_pop ();

  gtk_widget_show (mainwin);

}

static void
test_post_window ()
{
        mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	gtk_window_set_screen (GTK_WINDOW (mainwin), gdk_screen_get_default ());

        /* gtk_window_set_keep_above (GTK_WINDOW (mainwin), true); optional */
	/* test_set_wm_dock (); optional */

	gtk_widget_show_all (mainwin);
}