Multi-screen test case form multihead branch with a few cleanups. (Get rid

Tue Apr 30 15:59:53 2002  Owen Taylor  <otaylor@redhat.com>

        * tests/testmultiscreen.c: Multi-screen test case
        form multihead branch with a few cleanups. (Get rid
        of use of g_object_connect())

        * tests/testmultidisplay.c: Multi-display test case
        from multihead branch with a few improvements.
        (Allow the other display name to be passed on
        the command line, use a GtkDialog to get more attractive
        spacing.)
This commit is contained in:
Owen Taylor 2002-04-30 20:17:36 +00:00 committed by Owen Taylor
parent 75e535515a
commit d9aeb7bc7d
9 changed files with 396 additions and 0 deletions

View File

@ -1,3 +1,15 @@
Tue Apr 30 15:59:53 2002 Owen Taylor <otaylor@redhat.com>
* tests/testmultiscreen.c: Multi-screen test case
form multihead branch with a few cleanups. (Get rid
of use of g_object_connect())
* tests/testmultidisplay.c: Multi-display test case
from multihead branch with a few improvements.
(Allow the other display name to be passed on
the command line, use a GtkDialog to get more attractive
spacing.)
Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com> Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix * gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix

View File

@ -1,3 +1,15 @@
Tue Apr 30 15:59:53 2002 Owen Taylor <otaylor@redhat.com>
* tests/testmultiscreen.c: Multi-screen test case
form multihead branch with a few cleanups. (Get rid
of use of g_object_connect())
* tests/testmultidisplay.c: Multi-display test case
from multihead branch with a few improvements.
(Allow the other display name to be passed on
the command line, use a GtkDialog to get more attractive
spacing.)
Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com> Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix * gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix

View File

@ -1,3 +1,15 @@
Tue Apr 30 15:59:53 2002 Owen Taylor <otaylor@redhat.com>
* tests/testmultiscreen.c: Multi-screen test case
form multihead branch with a few cleanups. (Get rid
of use of g_object_connect())
* tests/testmultidisplay.c: Multi-display test case
from multihead branch with a few improvements.
(Allow the other display name to be passed on
the command line, use a GtkDialog to get more attractive
spacing.)
Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com> Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix * gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix

View File

@ -1,3 +1,15 @@
Tue Apr 30 15:59:53 2002 Owen Taylor <otaylor@redhat.com>
* tests/testmultiscreen.c: Multi-screen test case
form multihead branch with a few cleanups. (Get rid
of use of g_object_connect())
* tests/testmultidisplay.c: Multi-display test case
from multihead branch with a few improvements.
(Allow the other display name to be passed on
the command line, use a GtkDialog to get more attractive
spacing.)
Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com> Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix * gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix

View File

@ -1,3 +1,15 @@
Tue Apr 30 15:59:53 2002 Owen Taylor <otaylor@redhat.com>
* tests/testmultiscreen.c: Multi-screen test case
form multihead branch with a few cleanups. (Get rid
of use of g_object_connect())
* tests/testmultidisplay.c: Multi-display test case
from multihead branch with a few improvements.
(Allow the other display name to be passed on
the command line, use a GtkDialog to get more attractive
spacing.)
Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com> Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix * gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix

View File

@ -1,3 +1,15 @@
Tue Apr 30 15:59:53 2002 Owen Taylor <otaylor@redhat.com>
* tests/testmultiscreen.c: Multi-screen test case
form multihead branch with a few cleanups. (Get rid
of use of g_object_connect())
* tests/testmultidisplay.c: Multi-display test case
from multihead branch with a few improvements.
(Allow the other display name to be passed on
the command line, use a GtkDialog to get more attractive
spacing.)
Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com> Tue Apr 30 14:23:43 2002 Owen Taylor <otaylor@redhat.com>
* gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix * gdk/x11/gdkdisplay-x11.c (gdk_open_display): fix

View File

@ -30,6 +30,8 @@ noinst_PROGRAMS = \
testdnd \ testdnd \
testgtk \ testgtk \
testinput \ testinput \
testmultidisplay \
testmultiscreen \
testrgb \ testrgb \
testselection \ testselection \
$(testsocket_programs) \ $(testsocket_programs) \
@ -49,6 +51,8 @@ testcalendar_DEPENDENCIES = $(TEST_DEPS)
testdnd_DEPENDENCIES = $(TEST_DEPS) testdnd_DEPENDENCIES = $(TEST_DEPS)
testgtk_DEPENDENCIES = $(TEST_DEPS) testgtk_DEPENDENCIES = $(TEST_DEPS)
testinput_DEPENDENCIES = $(TEST_DEPS) testinput_DEPENDENCIES = $(TEST_DEPS)
testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
testmultiscreen_DEPENDENCIES = $(TEST_DEPS)
testrgb_DEPENDENCIES = $(TEST_DEPS) testrgb_DEPENDENCIES = $(TEST_DEPS)
testselection_DEPENDENCIES = $(TEST_DEPS) testselection_DEPENDENCIES = $(TEST_DEPS)
testsocket_DEPENDENCIES = $(DEPS) testsocket_DEPENDENCIES = $(DEPS)
@ -69,6 +73,8 @@ testcalendar_LDADD = $(LDADDS)
testdnd_LDADD = $(LDADDS) testdnd_LDADD = $(LDADDS)
testgtk_LDADD = $(LDADDS) testgtk_LDADD = $(LDADDS)
testinput_LDADD = $(LDADDS) testinput_LDADD = $(LDADDS)
testmultidisplay_LDADD = $(LDADDS)
testmultiscreen_LDADD = $(LDADDS)
testrgb_LDADD = $(LDADDS) testrgb_LDADD = $(LDADDS)
testselection_LDADD = $(LDADDS) testselection_LDADD = $(LDADDS)
testsocket_LDADD = $(LDADDS) testsocket_LDADD = $(LDADDS)

163
tests/testmultidisplay.c Normal file
View File

@ -0,0 +1,163 @@
#include <strings.h>
#include <gtk/gtk.h>
#include <gtk/gtkstock.h>
#include <gdk/gdk.h>
gchar *screen2_name = NULL;
typedef struct
{
GtkEntry *e1;
GtkEntry *e2;
}
MyDoubleGtkEntry;
void
get_screen_response (GtkDialog *dialog,
gint response_id,
GtkEntry *entry)
{
if (response_id == GTK_RESPONSE_DELETE_EVENT)
return;
if (screen2_name)
g_free (screen2_name);
screen2_name = g_strdup (gtk_entry_get_text (entry));
}
void
entry_dialog_response (GtkDialog *dialog,
gint response_id,
MyDoubleGtkEntry *de)
{
if (response_id == GTK_RESPONSE_APPLY)
gtk_entry_set_text (de->e2, gtk_entry_get_text (de->e1));
else
gtk_main_quit ();
}
void
make_selection_dialog (GdkScreen * screen,
GtkWidget * entry,
GtkWidget * other_entry)
{
GtkWidget *window, *vbox;
MyDoubleGtkEntry *double_entry = g_new (MyDoubleGtkEntry, 1);
double_entry->e1 = GTK_ENTRY (entry);
double_entry->e2 = GTK_ENTRY (other_entry);
if (!screen)
screen = gdk_get_default_screen ();
window = gtk_widget_new (GTK_TYPE_DIALOG,
"screen", screen,
"user_data", NULL,
"type", GTK_WINDOW_TOPLEVEL,
"title", "MultiDisplay Cut & Paste",
"border_width", 10, NULL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
vbox = gtk_widget_new (GTK_TYPE_VBOX,
"border_width", 5,
NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
gtk_widget_grab_focus (entry);
gtk_dialog_add_buttons (GTK_DIALOG (window),
GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
GTK_STOCK_QUIT, GTK_RESPONSE_DELETE_EVENT,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_APPLY);
g_signal_connect (G_OBJECT (window), "response",
G_CALLBACK (entry_dialog_response), double_entry);
gtk_widget_show_all (window);
}
int
main (int argc, char *argv[])
{
GtkWidget *dialog, *display_entry, *dialog_label;
GtkWidget *entry, *entry2;
GdkDisplay *dpy2;
GdkScreen *scr2 = NULL; /* Quiet GCC */
gboolean correct_second_display = FALSE;
gtk_init (&argc, &argv);
if (argc == 2)
screen2_name = g_strdup (argv[1]);
/* Get the second display information */
dialog = gtk_dialog_new_with_buttons ("Second Display Selection",
NULL,
GTK_DIALOG_MODAL,
GTK_STOCK_OK,
GTK_RESPONSE_OK, NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
display_entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (display_entry), TRUE);
dialog_label =
gtk_label_new ("Please enter the name of\nthe second display\n");
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), dialog_label);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
display_entry);
gtk_signal_connect (GTK_OBJECT (dialog), "response",
GTK_SIGNAL_FUNC (get_screen_response), display_entry);
gtk_widget_grab_focus (display_entry);
gtk_widget_show_all (GTK_BIN (dialog)->child);
while (!correct_second_display)
{
if (screen2_name)
{
if (!g_strcasecmp (screen2_name, ""))
g_printerr ("No display name, reverting to default display\n");
dpy2 = gdk_open_display (screen2_name);
if (dpy2)
{
scr2 = gdk_display_get_default_screen (dpy2);
correct_second_display = TRUE;
}
else
{
char *error_msg =
g_strdup_printf ("Can't open display :\n\t%s\nplease try another one\n",
screen2_name);
gtk_label_set_text (GTK_LABEL (dialog_label), error_msg);
g_free (error_msg);
}
}
if (!correct_second_display)
gtk_dialog_run (GTK_DIALOG (dialog));
}
gtk_widget_destroy (dialog);
entry = gtk_widget_new (GTK_TYPE_ENTRY,
"activates_default", TRUE,
"visible", TRUE,
NULL);
entry2 = gtk_widget_new (GTK_TYPE_ENTRY,
"activates_default", TRUE,
"visible", TRUE,
NULL);
/* for default display */
make_selection_dialog (NULL, entry2, entry);
/* for selected display */
make_selection_dialog (scr2, entry, entry2);
gtk_main ();
return 0;
}

155
tests/testmultiscreen.c Normal file
View File

@ -0,0 +1,155 @@
#include <gtk/gtk.h>
static GtkWidget **images;
static GtkWidget **vbox;
static void
hello (GtkWidget * button, char *label)
{
g_print ("Click from %s\n", label);
}
static void
show_hide (GtkWidget * button, gpointer data)
{
gint num_screen = GPOINTER_TO_INT (data);
static gboolean visible = TRUE;
if (visible)
{
gtk_widget_hide (images[num_screen]);
gtk_button_set_label (GTK_BUTTON (button), "Show Icon");
visible = FALSE;
}
else
{
gtk_widget_show (images[num_screen]);
gtk_button_set_label (GTK_BUTTON (button), "Hide Icon");
visible = TRUE;
}
}
static void
move (GtkWidget *button, GtkVBox *vbox)
{
GdkScreen *screen = gtk_widget_get_screen (button);
GtkWidget *toplevel = gtk_widget_get_toplevel (button);
GtkWidget *new_toplevel;
GdkDisplay *display = gdk_screen_get_display (screen);
gint number_of_screens = gdk_display_get_n_screens (display);
gint screen_num = gdk_screen_get_number (screen);
g_print ("This button is on screen %d\n", gdk_screen_get_number (screen));
new_toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
if ((screen_num +1) < number_of_screens)
gtk_window_set_screen (GTK_WINDOW (new_toplevel),
gdk_display_get_screen (display,
screen_num + 1));
else
gtk_window_set_screen (GTK_WINDOW (new_toplevel),
gdk_display_get_screen (display, 0));
gtk_widget_reparent (GTK_WIDGET (vbox), new_toplevel);
gtk_widget_destroy (toplevel);
gtk_widget_show_all (new_toplevel);
}
int
main (int argc, char *argv[])
{
GtkWidget **window;
GtkWidget *moving_window, *moving_button, *moving_vbox, *moving_image;
gint num_screen = 0;
gchar *displayname = NULL;
gint i;
GdkScreen **screen_list;
GdkDisplay *dpy;
GSList *ids;
gtk_init (&argc, &argv);
dpy = gdk_get_default_display ();
num_screen = gdk_display_get_n_screens (dpy);
displayname = g_strdup (gdk_display_get_name (dpy));
g_print ("This X Server (%s) manages %d screen(s).\n",
displayname, num_screen);
screen_list = g_new (GdkScreen *, num_screen);
window = g_new (GtkWidget *, num_screen);
images = g_new (GtkWidget *, num_screen);
vbox = g_new (GtkWidget *, num_screen);
ids = gtk_stock_list_ids ();
for (i = 0; i < num_screen; i++)
{
char *label = g_strdup_printf ("Screen %d", i);
GtkWidget *button;
screen_list[i] = gdk_display_get_screen (dpy, i);
window[i] = gtk_widget_new (GTK_TYPE_WINDOW,
"screen", screen_list[i],
"user_data", NULL,
"type", GTK_WINDOW_TOPLEVEL,
"title", label,
"allow_grow", FALSE,
"allow_shrink", FALSE,
"border_width", 10, NULL,
NULL);
g_signal_connect (window[i], "destroy",
G_CALLBACK (gtk_main_quit), NULL);
vbox[i] = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (window[i]), vbox[i]);
button = gtk_widget_new (GTK_TYPE_BUTTON,
"label", label,
"parent", vbox[i],
"visible", TRUE, NULL,
NULL);
g_signal_connect (button, "clicked",
G_CALLBACK (hello), label);
images[i] = gtk_image_new_from_stock (g_slist_nth (ids, i+1)->data,
GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (vbox[i]), images[i]);
button = gtk_widget_new (GTK_TYPE_BUTTON,
"label", "Hide Icon",
"parent", vbox[i],
"visible", TRUE, NULL,
NULL);
g_signal_connect (button, "clicked",
G_CALLBACK (show_hide), GINT_TO_POINTER (i));
}
for (i = 0; i < num_screen; i++)
gtk_widget_show_all (window[i]);
moving_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
moving_vbox = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (moving_window), moving_vbox);
moving_button = gtk_widget_new (GTK_TYPE_BUTTON,
"label", "Move to Next Screen",
"visible", TRUE,
NULL);
g_signal_connect (G_OBJECT (moving_button), "clicked",
G_CALLBACK (move), moving_vbox);
gtk_container_add (GTK_CONTAINER (moving_vbox), moving_button);
moving_image = gtk_image_new_from_stock (g_slist_nth (ids, num_screen + 2)->data,
GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (moving_vbox), moving_image);
gtk_widget_show_all (moving_window);
gtk_main ();
return 0;
}