2 * Copyright (C) 2001 Sun Microsystems Inc.
3 * Author: Erwann Chenede <erwann.chenede@sun.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 static GtkWidget
**images
;
25 static GtkWidget
**vbox
;
28 hello (GtkWidget
* button
, char *label
)
30 g_print ("Click from %s\n", label
);
34 show_hide (GtkWidget
* button
, gpointer data
)
36 gint num_screen
= GPOINTER_TO_INT (data
);
38 static gboolean visible
= TRUE
;
41 gtk_widget_hide (images
[num_screen
]);
42 gtk_button_set_label (GTK_BUTTON (button
), "Show Icon");
47 gtk_widget_show (images
[num_screen
]);
48 gtk_button_set_label (GTK_BUTTON (button
), "Hide Icon");
54 move (GtkWidget
*button
, GtkVBox
*vbox
)
56 GdkScreen
*screen
= gtk_widget_get_screen (button
);
57 GtkWidget
*toplevel
= gtk_widget_get_toplevel (button
);
58 GtkWidget
*new_toplevel
;
59 GdkDisplay
*display
= gdk_screen_get_display (screen
);
60 gint number_of_screens
= gdk_display_get_n_screens (display
);
61 gint screen_num
= gdk_screen_get_number (screen
);
63 g_print ("This button is on screen %d\n", gdk_screen_get_number (screen
));
65 new_toplevel
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
67 if ((screen_num
+1) < number_of_screens
)
68 gtk_window_set_screen (GTK_WINDOW (new_toplevel
),
69 gdk_display_get_screen (display
,
72 gtk_window_set_screen (GTK_WINDOW (new_toplevel
),
73 gdk_display_get_screen (display
, 0));
75 gtk_widget_reparent (GTK_WIDGET (vbox
), new_toplevel
);
76 gtk_widget_destroy (toplevel
);
77 gtk_widget_show_all (new_toplevel
);
82 main (int argc
, char *argv
[])
85 GtkWidget
*moving_window
, *moving_button
, *moving_vbox
, *moving_image
;
87 gchar
*displayname
= NULL
;
89 GdkScreen
**screen_list
;
93 gtk_init (&argc
, &argv
);
95 dpy
= gdk_display_get_default ();
96 num_screen
= gdk_display_get_n_screens (dpy
);
97 displayname
= g_strdup (gdk_display_get_name (dpy
));
98 g_print ("This X Server (%s) manages %d screen(s).\n",
99 displayname
, num_screen
);
100 screen_list
= g_new (GdkScreen
*, num_screen
);
101 window
= g_new (GtkWidget
*, num_screen
);
102 images
= g_new (GtkWidget
*, num_screen
);
103 vbox
= g_new (GtkWidget
*, num_screen
);
105 ids
= gtk_stock_list_ids ();
107 for (i
= 0; i
< num_screen
; i
++)
109 char *label
= g_strdup_printf ("Screen %d", i
);
112 screen_list
[i
] = gdk_display_get_screen (dpy
, i
);
114 window
[i
] = g_object_new (GTK_TYPE_WINDOW
,
115 "screen", screen_list
[i
],
117 "type", GTK_WINDOW_TOPLEVEL
,
120 "allow_shrink", FALSE
,
121 "border_width", 10, NULL
,
123 g_signal_connect (window
[i
], "destroy",
124 G_CALLBACK (gtk_main_quit
), NULL
);
126 vbox
[i
] = gtk_vbox_new (TRUE
, 0);
127 gtk_container_add (GTK_CONTAINER (window
[i
]), vbox
[i
]);
129 button
= g_object_new (GTK_TYPE_BUTTON
,
132 "visible", TRUE
, NULL
,
134 g_signal_connect (button
, "clicked",
135 G_CALLBACK (hello
), label
);
137 images
[i
] = gtk_image_new_from_stock (g_slist_nth (ids
, i
+1)->data
,
138 GTK_ICON_SIZE_BUTTON
);
140 gtk_container_add (GTK_CONTAINER (vbox
[i
]), images
[i
]);
142 button
= g_object_new (GTK_TYPE_BUTTON
,
143 "label", "Hide Icon",
145 "visible", TRUE
, NULL
,
147 g_signal_connect (button
, "clicked",
148 G_CALLBACK (show_hide
), GINT_TO_POINTER (i
));
151 for (i
= 0; i
< num_screen
; i
++)
152 gtk_widget_show_all (window
[i
]);
154 moving_window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
155 moving_vbox
= gtk_vbox_new (TRUE
, 0);
157 gtk_container_add (GTK_CONTAINER (moving_window
), moving_vbox
);
158 moving_button
= g_object_new (GTK_TYPE_BUTTON
,
159 "label", "Move to Next Screen",
163 g_signal_connect (moving_button
, "clicked",
164 G_CALLBACK (move
), moving_vbox
);
166 gtk_container_add (GTK_CONTAINER (moving_vbox
), moving_button
);
168 moving_image
= gtk_image_new_from_stock (g_slist_nth (ids
, num_screen
+ 2)->data
,
169 GTK_ICON_SIZE_BUTTON
);
170 gtk_container_add (GTK_CONTAINER (moving_vbox
), moving_image
);
171 gtk_widget_show_all (moving_window
);