summaryrefslogtreecommitdiff
path: root/src/test-window.c
blob: 1a5fd42f6078eb1ace6cc0bc9e0e0ffad9d1a1d6 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * Authors: William Jon McCann <mccann@jhu.edu>
 *
 */

#include "config.h"

#include <stdlib.h>

#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "gs-window.h"
#include "gs-grab.h"
#include "gs-debug.h"

static GSGrab *grab = NULL;

static void
window_deactivated_cb (GSWindow  *window,
                       gpointer   data)
{
	gs_window_destroy (window);
}

static void
window_dialog_up_cb (GSWindow  *window,
                     gpointer   data)
{
}

static void
window_dialog_down_cb (GSWindow  *window,
                       gpointer   data)
{
}

static void
window_show_cb (GSWindow  *window,
                gpointer   data)
{
	/* move devices grab so that dialog can be used */
	gs_grab_move_to_window (grab,
	                        gs_window_get_gdk_window (window),
	                        gs_window_get_display (window),
	                        TRUE, FALSE);
}

static gboolean
window_activity_cb (GSWindow  *window,
                    gpointer   data)
{
	gs_window_request_unlock (window);

	return TRUE;
}

static void
disconnect_window_signals (GSWindow *window)
{
	gpointer data;

	data = NULL;
	g_signal_handlers_disconnect_by_func (window, window_activity_cb, data);
	g_signal_handlers_disconnect_by_func (window, window_deactivated_cb, data);
	g_signal_handlers_disconnect_by_func (window, window_dialog_up_cb, data);
	g_signal_handlers_disconnect_by_func (window, window_dialog_down_cb, data);
	g_signal_handlers_disconnect_by_func (window, window_show_cb, data);
}

static void
window_destroyed_cb (GtkWindow *window,
                     gpointer   data)
{
	disconnect_window_signals (GS_WINDOW (window));
	gs_grab_release (grab, TRUE);
	gtk_main_quit ();
}

static void
connect_window_signals (GSWindow *window)
{
	gpointer data;

	data = NULL;

	g_signal_connect_object (window, "activity",
	                         G_CALLBACK (window_activity_cb), data, 0);
	g_signal_connect_object (window, "destroy",
	                         G_CALLBACK (window_destroyed_cb), data, 0);
	g_signal_connect_object (window, "deactivated",
	                         G_CALLBACK (window_deactivated_cb), data, 0);
	g_signal_connect_object (window, "dialog-up",
	                         G_CALLBACK (window_dialog_up_cb), data, 0);
	g_signal_connect_object (window, "dialog-down",
	                         G_CALLBACK (window_dialog_down_cb), data, 0);
	g_signal_connect_object (window, "show",
	                         G_CALLBACK (window_show_cb), data, 0);
}

static void
test_window (void)
{
	GSWindow   *window;
	gboolean    lock_active;
	gboolean    user_switch_enabled;
	GdkDisplay *display;
#if GTK_CHECK_VERSION (3, 22, 0)
	GdkMonitor *monitor;
#else
	GdkScreen  *screen;
	int         monitor;
#endif

	lock_active = TRUE;
	user_switch_enabled = TRUE;
	display = gdk_display_get_default ();
#if GTK_CHECK_VERSION (3, 22, 0)
	monitor = gdk_display_get_primary_monitor (display);
#else
	screen = gdk_display_get_default_screen (display);
	monitor = gdk_screen_get_primary_monitor (screen);
#endif

	window = gs_window_new (display, monitor, lock_active);

	gs_window_set_user_switch_enabled (window, user_switch_enabled);

	connect_window_signals (window);

	gs_window_show (window);
}

int
main (int    argc,
      char **argv)
{
	GError *error = NULL;

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
# endif
	textdomain (GETTEXT_PACKAGE);
#endif

	if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error))
	{
		fprintf (stderr, "%s", error->message);
		g_error_free (error);
		exit (1);
	}

	gs_debug_init (TRUE, FALSE);

	grab = gs_grab_new ();

	test_window ();

	/* safety valve in case we can't authenticate */
	g_timeout_add (30000, (GSourceFunc)gtk_main_quit, NULL);

	gtk_main ();

	g_object_unref (grab);

	gs_debug_shutdown ();

	return 0;
}