## Multi-head Support Overview Multi-head Support Overview — Overview of GdkDisplay and GdkScreen |

## Overview

Multihead support is based around two main object types:

- GdkDisplay

- GdkScreen

GdkDisplay objects are the GDK representation of the X Display which can be described as a workstation consisting of a keyboard a pointing device (such as a mouse) and one or more screens. It is used to open and keep track of various GdkScreen objects currently instanciated by the application. It is also used to grab and release the keyboard and the mouse pointer.

GdkScreen objects are the GDK representation of a physical screen. It is used throughout GDK and GTK+ to specify which screen the top level windows are to be displayed on. It is also used to query the screen specification and default settings such as the default colormap (gdk_screen_get_default_colormap()), the screen width (gdk_screen_get_width()), etc.

The following code samples demonstrate common usage of the objects described above.

Example 2. Testing the number of screen on the current display

    gint num_screen = 0;
    gchar *displayname = NULL;
    GdkScreen **screen_list;
    GdkDisplay *display;

    gtk_init (&argc, &argv);

    display = gdk_display_get_default ();
    num_screen = gdk_display_get_n_screens (display);
    displayname = gdk_display_get_name (display);
    if (num_screen <= 1)
      {
        printf ("This Xserver (%s) manages only one screen. exiting...\n",
                displayname);
        exit (1);
      }
    else
      {
        printf ("This Xserver (%s) manages %d screens.\n", displayname,
                num_screen);
      }

Example 3. Opening a second display

    gchar *second_screen_name;
    GdkDisplay *second_display;
    GdkScreen *second_screen;
    GtkWidget *window;

    gtk_init (&argc, &argv);

    /* screen2_name needs to be initialized before calling
    /* gdk_display_new() */
    second_display = gdk_display_new (&argc, &argv, second_screen_name);
    if (second_display)
        second_screen = gdk_display_get_default_screen (second_display);
    else
      {
    	g_print ("Can't open display :\n\t%s\n\n",
    		  second_screen_name);
        exit (1);
      }
    /* now GdkScreen can be assigned to GtkWindows */

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_screen (window, second_screen);

## See Also

GdkDisplay | the GDK Object used to represent and manipulate display related data
GdkScreen | the GDK Object used to represent and query screen related data