gtk-demo: Remove multiscreen support

There's only one screen per display, so no need to let users select from
a list of that 1 screen.
This commit is contained in:
Benjamin Otte 2013-04-02 14:38:24 +02:00
parent 6a90c48ea6
commit f2263afb19

View File

@ -1,24 +1,23 @@
/* Change Display /* Change Display
* *
* Demonstrates migrating a window between different displays and * Demonstrates migrating a window between different displays.
* screens. A display is a mouse and keyboard with some number of * A display is a mouse and keyboard with some number of
* associated monitors. A screen is a set of monitors grouped * associated monitors. The neat thing about having multiple
* into a single physical work area. The neat thing about having * displays is that they can be on a completely separate
* multiple displays is that they can be on a completely separate
* computers, as long as there is a network connection to the * computers, as long as there is a network connection to the
* computer where the application is running. * computer where the application is running.
* *
* Only some of the windowing systems where GTK+ runs have the * Only some of the windowing systems where GTK+ runs have the
* concept of multiple displays and screens. (The X Window System * concept of multiple displays. (The X Window System is the
* is the main example.) Other windowing systems can only * main example.) Other windowing systems can only handle one
* handle one keyboard and mouse, and combine all monitors into * keyboard and mouse, and combine all monitors into
* a single screen. * a single display.
* *
* This is a moderately complex example, and demonstrates: * This is a moderately complex example, and demonstrates:
* *
* - Tracking the currently open displays and screens * - Tracking the currently open displays
* *
* - Changing the screen for a window * - Changing the display for a window
* *
* - Letting the user choose a window by clicking on it * - Letting the user choose a window by clicking on it
* *
@ -45,11 +44,8 @@ struct _ChangeDisplayInfo
GtkSizeGroup *size_group; GtkSizeGroup *size_group;
GtkTreeModel *display_model; GtkTreeModel *display_model;
GtkTreeModel *screen_model;
GtkTreeSelection *screen_selection;
GdkDisplay *current_display; GdkDisplay *current_display;
GdkScreen *current_screen;
}; };
/* These enumerations provide symbolic names for the columns /* These enumerations provide symbolic names for the columns
@ -177,40 +173,11 @@ query_change_display (ChangeDisplayInfo *info)
"to move to the new screen"); "to move to the new screen");
if (toplevel) if (toplevel)
gtk_window_set_screen (GTK_WINDOW (toplevel), info->current_screen); gtk_window_set_screen (GTK_WINDOW (toplevel), gdk_display_get_screen (info->current_display, 0));
else else
gdk_display_beep (gdk_screen_get_display (screen)); gdk_display_beep (gdk_screen_get_display (screen));
} }
/* Fills in the screen list based on the current display
*/
static void
fill_screens (ChangeDisplayInfo *info)
{
gtk_list_store_clear (GTK_LIST_STORE (info->screen_model));
if (info->current_display)
{
gint n_screens = gdk_display_get_n_screens (info->current_display);
gint i;
for (i = 0; i < n_screens; i++)
{
GdkScreen *screen = gdk_display_get_screen (info->current_display, i);
GtkTreeIter iter;
gtk_list_store_append (GTK_LIST_STORE (info->screen_model), &iter);
gtk_list_store_set (GTK_LIST_STORE (info->screen_model), &iter,
SCREEN_COLUMN_NUMBER, i,
SCREEN_COLUMN_SCREEN, screen,
-1);
if (i == 0)
gtk_tree_selection_select_iter (info->screen_selection, &iter);
}
}
}
/* Called when the user clicks on a button in our dialog or /* Called when the user clicks on a button in our dialog or
* closes the dialog through the window manager. Unless the * closes the dialog through the window manager. Unless the
* "Change" button was clicked, we destroy the dialog. * "Change" button was clicked, we destroy the dialog.
@ -320,28 +287,6 @@ display_changed_cb (GtkTreeSelection *selection,
-1); -1);
else else
info->current_display = NULL; info->current_display = NULL;
fill_screens (info);
}
/* Called when the selected row in the sceen list changes.
* Updates info->current_screen.
*/
static void
screen_changed_cb (GtkTreeSelection *selection,
ChangeDisplayInfo *info)
{
GtkTreeModel *model;
GtkTreeIter iter;
if (info->current_screen)
g_object_unref (info->current_screen);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
gtk_tree_model_get (model, &iter,
SCREEN_COLUMN_SCREEN, &info->current_screen,
-1);
else
info->current_screen = NULL;
} }
/* This function is used both for creating the "Display" and /* This function is used both for creating the "Display" and
@ -446,37 +391,6 @@ create_display_frame (ChangeDisplayInfo *info)
return frame; return frame;
} }
/* Creates the "Screen" frame in the main window.
*/
GtkWidget *
create_screen_frame (ChangeDisplayInfo *info)
{
GtkWidget *frame;
GtkWidget *tree_view;
GtkWidget *button_vbox;
GtkTreeViewColumn *column;
create_frame (info, "Screen", &frame, &tree_view, &button_vbox);
info->screen_model = (GtkTreeModel *)gtk_list_store_new (SCREEN_NUM_COLUMNS,
G_TYPE_INT,
GDK_TYPE_SCREEN);
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), info->screen_model);
column = gtk_tree_view_column_new_with_attributes ("Number",
gtk_cell_renderer_text_new (),
"text", SCREEN_COLUMN_NUMBER,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
info->screen_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
g_signal_connect (info->screen_selection, "changed",
G_CALLBACK (screen_changed_cb), info);
return frame;
}
/* Called when one of the currently open displays is closed. /* Called when one of the currently open displays is closed.
* Remove it from our list of displays. * Remove it from our list of displays.
*/ */
@ -580,12 +494,9 @@ destroy_info (ChangeDisplayInfo *info)
g_object_unref (info->size_group); g_object_unref (info->size_group);
g_object_unref (info->display_model); g_object_unref (info->display_model);
g_object_unref (info->screen_model);
if (info->current_display) if (info->current_display)
g_object_unref (info->current_display); g_object_unref (info->current_display);
if (info->current_screen)
g_object_unref (info->current_screen);
g_free (info); g_free (info);
} }
@ -637,9 +548,6 @@ do_changedisplay (GtkWidget *do_widget)
frame = create_display_frame (info); frame = create_display_frame (info);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
frame = create_screen_frame (info);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
initialize_displays (info); initialize_displays (info);
gtk_widget_show_all (info->window); gtk_widget_show_all (info->window);