gdkdisplaymanager-wayland.c 2.85 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* GDK - The GIMP Drawing Kit
 * gdkdisplaymanager-wayland.c
 *
 * Copyright 2010 Red Hat, Inc.
 *
 * Author: Matthias clasen
 *
 * 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
Javier Jardón's avatar
Javier Jardón committed
19
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Kristian Høgsberg's avatar
Kristian Høgsberg committed
20 21 22 23 24 25 26
 */

#include "config.h"

#include "gdkdisplaymanagerprivate.h"
#include "gdkdisplay-wayland.h"
#include "gdkprivate-wayland.h"
27
#include "gdkwayland.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
28 29 30 31 32 33 34
#include "gdkinternals.h"

struct _GdkWaylandDisplayManager
{
  GdkDisplayManager parent;

  GSList *displays;
35

36
  gboolean init_failed;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
37 38 39 40 41 42 43
};

struct _GdkWaylandDisplayManagerClass
{
  GdkDisplayManagerClass parent_class;
};

44 45 46 47 48 49 50 51 52 53 54 55
static void g_initable_iface_init (GInitableIface *iface);

G_DEFINE_TYPE_WITH_CODE (GdkWaylandDisplayManager, gdk_wayland_display_manager, GDK_TYPE_DISPLAY_MANAGER,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, g_initable_iface_init))

static gboolean
gdk_wayland_display_manager_initable_init (GInitable     *initable,
                                           GCancellable  *cancellable,
                                           GError       **error)
{
  struct wl_display *wl_display;

56 57 58 59 60 61
  /* Set by the compositor when launching a special client - and it gets reset
   * by wl_display_connect so we must avoid calling it twice
   */
  if (g_getenv ("WAYLAND_SOCKET"))
    return TRUE;

62 63 64 65 66
  /* check that a connection to the default display is possible */
  wl_display = wl_display_connect (gdk_get_display_arg_name ());

  if (!wl_display)
    {
67
      GDK_WAYLAND_DISPLAY_MANAGER (initable)->init_failed = TRUE;
68 69 70
      return FALSE;
    }

71 72
  wl_display_disconnect (wl_display);

73 74 75 76 77 78 79 80
  return TRUE;
}

void
g_initable_iface_init (GInitableIface *iface)
{
  iface->init = gdk_wayland_display_manager_initable_init;
}
Kristian Høgsberg's avatar
Kristian Høgsberg committed
81 82 83 84

static void
gdk_wayland_display_manager_finalize (GObject *object)
{
85 86 87
  if (GDK_WAYLAND_DISPLAY_MANAGER (object)->init_failed == FALSE)
    g_error ("A GdkWaylandDisplayManager object was finalized. This should not happen");

Kristian Høgsberg's avatar
Kristian Høgsberg committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  G_OBJECT_CLASS (gdk_wayland_display_manager_parent_class)->finalize (object);
}

static void
gdk_wayland_display_manager_class_init (GdkWaylandDisplayManagerClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);

  object_class->finalize = gdk_wayland_display_manager_finalize;
}

static void
gdk_wayland_display_manager_init (GdkWaylandDisplayManager *manager)
{
}