<chapter id="gtk-x11">
  <title>GTK for the X Window System</title>
  <para>
    On UNIX, the X backend is enabled by default, so you don’t need to
    do anything special when compiling it, and everything should
    <quote>just work.</quote>
  </para>
  <para>
    To mix low-level Xlib routines into a GTK program, see
    <link linkend="gdk-X-Window-System-Interaction">GDK X Window System
    interaction</link> in the GDK manual.
  </para>
  <sect1 id="x11-envar">
    <title>X11-specific environment variables</title>
    <para>
      : The X11 GDK backend can be influenced with some additional
      environment variables.
    </para>
    <sect2>
      <title>GDK_SYNCHRONIZE</title>
      <para>
        If set, GDK makes all X requests synchronously. This is a useful
        option for debugging, but it will slow down the performance
        considerably.
      </para>
    </sect2>
    <sect2>
      <title>GDK_SCALE</title>
      <para>
        Must be set to an integer, typically 2. If set, GDK will scale
        all windows by the specified factor. Scaled output is meant to
        be used on high-dpi displays. Normally, GDK will pick up a
        suitable scale factor for each monitor from the display system.
        This environment variable allows to override that.
      </para>
    </sect2>
  </sect1>
  <sect1 id="gtk-X11-arch">
    <title>Understanding the X11 architecture</title>
    <para>
      People coming from a Windows or MacOS background often find
      certain aspects of the X Window System surprising. This section
      introduces some basic X concepts at a high level. For more
      details, the book most people use is called the <quote>Xlib
      Programming Manual</quote> by Adrian Nye; this book is volume one
      in the O’Reilly X Window System series.
    </para>
    <para>
      Standards are another important resource if you’re poking in
      low-level X11 details, in particular the ICCCM and the Extended
      Window Manager Hints specifications.
      <ulink url="http://www.freedesktop.org/standards/">freedesktop.org</ulink>
      has links to many relevant specifications.
    </para>
    <para>
      The GDK manual covers
      <link linkend="gdk-X-Window-System-Interaction">using Xlib in a
      GTK program</link>.
    </para>
    <sect2>
      <title>Server, client, window manager</title>
      <para>
        Other window systems typically put all their functionality in
        the application itself. With X, each application involves three
        different programs: the <emphasis>X server</emphasis>, the
        application (called a <emphasis>client</emphasis> because it’s a
        client of the X server), and a special client called the
        <emphasis>window manager</emphasis>.
      </para>
      <para>
        The X server is in charge of managing resources, processing
        drawing requests, and dispatching events such as keyboard and
        mouse events to interested applications. So client applications
        can ask the X server to create a window, draw a circle, or move
        windows around.
      </para>
      <para>
        The window manager is in charge of rendering the frame or
        borders around windows; it also has final say on the size of
        each window, and window states such as minimized, maximized, and
        so forth. On Windows and MacOS the application handles most of
        this. On X11, if you wish to modify the window’s state, or
        change its frame, you must ask the window manager to do so on
        your behalf, using an established
        <ulink url="http://www.freedesktop.org/standards/">convention</ulink>.
      </para>
      <para>
        GTK has functions for asking the window manager to do various
        things; see for example <link linkend="gtk-window-minimize"><function>gtk_window_minimize()</function></link> or
        <link linkend="gtk-window-maximize"><function>gtk_window_maximize()</function></link>. Keep in mind that most window managers
        <emphasis>will</emphasis> ignore certain requests from time to
        time, in the interests of good user interface.
      </para>
    </sect2>
  </sect1>
</chapter>
