summaryrefslogtreecommitdiffstats
path: root/subprojects/shew/src/shew-external-window.c
blob: 118d93fa401a9d1d4d637e4c806cc49556f3271c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * Copyright © 2016 Red Hat, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Jonas Ådahl <jadahl@redhat.com>
 */

#include <string.h>

#include "shew-external-window.h"
#include "shew-external-window-x11.h"
#include "shew-external-window-wayland.h"

enum
{
  PROP_0,

  PROP_DISPLAY,
};

typedef struct _ShewExternalWindowPrivate
{
  GdkDisplay *display;
} ShewExternalWindowPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (ShewExternalWindow, shew_external_window, G_TYPE_OBJECT)

ShewExternalWindow *
shew_external_window_new_from_handle (const char *handle_str)
{
#ifdef GDK_WINDOWING_X11
    {
      const char x11_prefix[] = "x11:";
      if (g_str_has_prefix (handle_str, x11_prefix))
        {
          ShewExternalWindowX11 *external_window_x11;
          const char *x11_handle_str = handle_str + strlen (x11_prefix);

          external_window_x11 = shew_external_window_x11_new (x11_handle_str);
          return SHEW_EXTERNAL_WINDOW (external_window_x11);
        }
    }
#endif
#ifdef GDK_WINDOWING_WAYLAND
    {
      const char wayland_prefix[] = "wayland:";
      if (g_str_has_prefix (handle_str, wayland_prefix))
        {
          ShewExternalWindowWayland *external_window_wayland;
          const char *wayland_handle_str = handle_str + strlen (wayland_prefix);

          external_window_wayland =
            shew_external_window_wayland_new (wayland_handle_str);
          return SHEW_EXTERNAL_WINDOW (external_window_wayland);
        }
    }
#endif

  g_warning ("Unhandled parent window type %s\n", handle_str);
  return NULL;
}

void
shew_external_window_set_parent_of (ShewExternalWindow *external_window,
                                    GdkSurface         *child_surface)
{
  SHEW_EXTERNAL_WINDOW_GET_CLASS (external_window)->set_parent_of (external_window,
                                                                   child_surface);
}

/**
 * shew_external_window_get_display:
 * Returns: (transfer none)
 */
GdkDisplay *
shew_external_window_get_display (ShewExternalWindow *external_window)
{
  ShewExternalWindowPrivate *priv =
    shew_external_window_get_instance_private (external_window);

  return priv->display;
}

static void
shew_external_window_set_property (GObject      *object,
                                   guint         prop_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  ShewExternalWindow *external_window = SHEW_EXTERNAL_WINDOW (object);
  ShewExternalWindowPrivate *priv =
    shew_external_window_get_instance_private (external_window);

  switch (prop_id)
    {
    case PROP_DISPLAY:
      g_set_object (&priv->display, g_value_get_object (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
shew_external_window_get_property (GObject    *object,
                                   guint       prop_id,
                                   GValue     *value,
                                   GParamSpec *pspec)
{
  ShewExternalWindow *external_window = SHEW_EXTERNAL_WINDOW (object);
  ShewExternalWindowPrivate *priv =
    shew_external_window_get_instance_private (external_window);

  switch (prop_id)
    {
    case PROP_DISPLAY:
      g_value_set_object (value, priv->display);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
shew_external_window_init (ShewExternalWindow *external_window)
{
}

static void
shew_external_window_class_init (ShewExternalWindowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->get_property = shew_external_window_get_property;
  object_class->set_property = shew_external_window_set_property;

  g_object_class_install_property (object_class,
                                   PROP_DISPLAY,
                                   g_param_spec_object ("display",
                                                        "GdkDisplay",
                                                        "The GdkDisplay instance",
                                                        GDK_TYPE_DISPLAY,
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY |
                                                        G_PARAM_STATIC_STRINGS));
}