2005-07-13 05:44:22 +00:00
|
|
|
/* testmultidisplay.c
|
|
|
|
* Copyright (C) 2001 Sun Microsystems Inc.
|
|
|
|
* Author: Erwann Chenede <erwann.chenede@sun.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2002-04-30 20:17:36 +00:00
|
|
|
#include <gtk/gtk.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;
|
2007-03-09 21:57:37 +00:00
|
|
|
g_free (screen2_name);
|
2002-04-30 20:17:36 +00:00
|
|
|
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;
|
2010-06-03 07:36:39 +00:00
|
|
|
GtkWidget *content_area;
|
2002-04-30 20:17:36 +00:00
|
|
|
MyDoubleGtkEntry *double_entry = g_new (MyDoubleGtkEntry, 1);
|
|
|
|
double_entry->e1 = GTK_ENTRY (entry);
|
|
|
|
double_entry->e2 = GTK_ENTRY (other_entry);
|
|
|
|
|
|
|
|
if (!screen)
|
2002-06-20 23:59:27 +00:00
|
|
|
screen = gdk_screen_get_default ();
|
2002-04-30 20:17:36 +00:00
|
|
|
|
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
|
|
|
window = g_object_new (GTK_TYPE_DIALOG,
|
2002-04-30 20:17:36 +00:00
|
|
|
"screen", screen,
|
|
|
|
"user_data", NULL,
|
|
|
|
"type", GTK_WINDOW_TOPLEVEL,
|
|
|
|
"title", "MultiDisplay Cut & Paste",
|
2016-10-09 00:32:00 +00:00
|
|
|
NULL);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2002-04-30 20:17:36 +00:00
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
|
|
|
|
2010-06-03 07:36:39 +00:00
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
|
2002-04-30 20:17:36 +00:00
|
|
|
|
2011-06-07 22:39:15 +00:00
|
|
|
vbox = g_object_new (GTK_TYPE_BOX,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
2002-04-30 20:17:36 +00:00
|
|
|
NULL);
|
2016-10-02 15:37:22 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (content_area), vbox, FALSE, FALSE);
|
2002-04-30 20:17:36 +00:00
|
|
|
|
2016-10-02 15:37:22 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE);
|
2002-04-30 20:17:36 +00:00
|
|
|
gtk_widget_grab_focus (entry);
|
|
|
|
|
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (window),
|
2013-06-24 21:31:22 +00:00
|
|
|
"_Apply", GTK_RESPONSE_APPLY,
|
|
|
|
"_Quit", GTK_RESPONSE_DELETE_EVENT,
|
2002-04-30 20:17:36 +00:00
|
|
|
NULL);
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_APPLY);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (window, "response",
|
2002-04-30 20:17:36 +00:00
|
|
|
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;
|
2010-06-03 07:36:39 +00:00
|
|
|
GtkWidget *content_area;
|
2002-04-30 20:17:36 +00:00
|
|
|
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,
|
2013-06-24 21:31:22 +00:00
|
|
|
"_OK",
|
2002-04-30 20:17:36 +00:00
|
|
|
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");
|
|
|
|
|
2010-06-03 07:36:39 +00:00
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (content_area), dialog_label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (content_area), display_entry);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (get_screen_response), display_entry);
|
2002-04-30 20:17:36 +00:00
|
|
|
|
|
|
|
gtk_widget_grab_focus (display_entry);
|
2010-05-24 20:31:36 +00:00
|
|
|
gtk_widget_show_all (gtk_bin_get_child (GTK_BIN (dialog)));
|
2002-04-30 20:17:36 +00:00
|
|
|
|
|
|
|
while (!correct_second_display)
|
|
|
|
{
|
|
|
|
if (screen2_name)
|
|
|
|
{
|
2002-10-13 23:22:33 +00:00
|
|
|
if (!g_ascii_strcasecmp (screen2_name, ""))
|
2002-04-30 20:17:36 +00:00
|
|
|
g_printerr ("No display name, reverting to default display\n");
|
|
|
|
|
2002-06-20 23:59:27 +00:00
|
|
|
dpy2 = gdk_display_open (screen2_name);
|
2002-04-30 20:17:36 +00:00
|
|
|
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);
|
|
|
|
|
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
|
|
|
entry = g_object_new (GTK_TYPE_ENTRY,
|
2002-04-30 20:17:36 +00:00
|
|
|
"activates_default", TRUE,
|
|
|
|
"visible", TRUE,
|
|
|
|
NULL);
|
Use g_object_new instead of gtk_widget_new
2008-06-19 Johan Dahlin <jdahlin@async.com.br>
* demos/testpixbuf.c (new_testrgb_window):
* gtk/gtkctree.c (gtk_ctree_new_with_titles):
* gtk/gtkitemfactory.c (gtk_item_factory_construct),
(gtk_item_factory_create_item):
* gtk/gtkmenu.c (gtk_menu_set_tearoff_state):
* gtk/gtkprogressbar.c (gtk_progress_bar_new),
(gtk_progress_bar_new_with_adjustment):
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_new):
* gtk/gtktext.c (gtk_text_new):
* gtk/gtkviewport.c (gtk_viewport_new):
* tests/simple.c (main):
* tests/testgtk.c (create_statusbar), (create_get_image),
(create_saved_position), (create_tooltips), (create_cursors),
(create_display_screen), (create_progress_bar), (create_idle_test):
* tests/testmultidisplay.c (make_selection_dialog), (main):
* tests/testmultiscreen.c (main):
* tests/testrgb.c (new_testrgb_window):
Use g_object_new instead of gtk_widget_new
svn path=/trunk/; revision=20462
2008-06-19 12:25:19 +00:00
|
|
|
entry2 = g_object_new (GTK_TYPE_ENTRY,
|
2002-04-30 20:17:36 +00:00
|
|
|
"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;
|
|
|
|
}
|