screen.c 2.39 KB
Newer Older
rhp's avatar
...  
rhp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* Metacity X screen handler */

/* 
 * Copyright (C) 2001 Havoc Pennington
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
#include "screen.h"
#include "util.h"
rhp's avatar
...  
rhp committed
23
#include "errors.h"
rhp's avatar
...  
rhp committed
24 25 26 27 28 29

MetaScreen*
meta_screen_new (MetaDisplay *display,
                 int          number)
{
  MetaScreen *screen;
rhp's avatar
...  
rhp committed
30 31
  Window xroot;
  Display *xdisplay;
rhp's avatar
...  
rhp committed
32

rhp's avatar
...  
rhp committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  /* Only display->name, display->xdisplay, and display->error_traps
   * can really be used in this function, since normally screens are
   * created from the MetaDisplay constructor
   */
  
  xdisplay = display->xdisplay;
  
  meta_verbose ("Trying screen %d on display '%s'\n",
                number, display->name);

  xroot = RootWindow (xdisplay, number);

  /* FVWM checks for None here, I don't know if this
   * ever actually happens
   */
  if (xroot == None)
    {
      meta_warning (_("Screen %d on display '%s' is invalid\n"),
                    number, display->name);
      return NULL;
    }

  /* Select our root window events */
  meta_error_trap_push (display);
  XSelectInput (xdisplay,
                xroot,
                SubstructureRedirectMask | SubstructureNotifyMask |
                ColormapChangeMask | PropertyChangeMask |
                LeaveWindowMask | EnterWindowMask |
                ButtonPressMask | ButtonReleaseMask);
  if (meta_error_trap_pop (display) != Success)
    {
      meta_warning (_("Screen %d on display '%s' already has a window manager\n"),
                    number, display->name);
      return NULL;
    }
rhp's avatar
...  
rhp committed
69 70 71
  
  screen = g_new (MetaScreen, 1);

rhp's avatar
...  
rhp committed
72
  screen->display = NULL;
rhp's avatar
...  
rhp committed
73
  screen->number = number;
rhp's avatar
...  
rhp committed
74 75
  screen->xscreen = ScreenOfDisplay (xdisplay, number);
  screen->xroot = xroot;  
rhp's avatar
...  
rhp committed
76 77 78 79 80 81 82 83 84 85 86
  
  return screen;
}

void
meta_screen_free (MetaScreen *screen)
{
  g_free (screen);
}