wayland: Make MetaWaylandOutput a GObject

This way we can later add signals to it.

https://bugzilla.gnome.org/show_bug.cgi?id=744453
This commit is contained in:
Jonas Ådahl 2015-04-17 17:17:46 +08:00
parent 1576b7d5a6
commit dc99af40f3
2 changed files with 68 additions and 18 deletions

View File

@ -31,6 +31,8 @@
#include <string.h>
G_DEFINE_TYPE (MetaWaylandOutput, meta_wayland_output, G_TYPE_OBJECT)
static void
output_resource_destroy (struct wl_resource *res)
{
@ -99,16 +101,8 @@ static void
wayland_output_destroy_notify (gpointer data)
{
MetaWaylandOutput *wayland_output = data;
GList *resources;
/* Make sure the destructors don't mess with the list */
resources = wayland_output->resources;
wayland_output->resources = NULL;
wl_global_destroy (wayland_output->global);
g_list_free (resources);
g_slice_free (MetaWaylandOutput, wayland_output);
g_object_unref (wayland_output);
}
static inline enum wl_output_transform
@ -165,6 +159,20 @@ wayland_output_update_for_output (MetaWaylandOutput *wayland_output,
wayland_output->transform = wl_transform;
}
static MetaWaylandOutput *
meta_wayland_output_new (MetaWaylandCompositor *compositor)
{
MetaWaylandOutput *wayland_output;
wayland_output = g_object_new (META_TYPE_WAYLAND_OUTPUT, NULL);
wayland_output->global = wl_global_create (compositor->wayland_display,
&wl_output_interface,
META_WL_OUTPUT_VERSION,
wayland_output, bind_output);
return wayland_output;
}
static GHashTable *
meta_wayland_compositor_update_outputs (MetaWaylandCompositor *compositor,
MetaMonitorManager *monitors)
@ -191,13 +199,7 @@ meta_wayland_compositor_update_outputs (MetaWaylandCompositor *compositor,
g_hash_table_steal (compositor->outputs, GSIZE_TO_POINTER (info->winsys_id));
}
else
{
wayland_output = g_slice_new0 (MetaWaylandOutput);
wayland_output->global = wl_global_create (compositor->wayland_display,
&wl_output_interface,
META_WL_OUTPUT_VERSION,
wayland_output, bind_output);
}
wayland_output = meta_wayland_output_new (compositor);
wayland_output_update_for_output (wayland_output, info);
g_hash_table_insert (new_table, GSIZE_TO_POINTER (info->winsys_id), wayland_output);
@ -214,6 +216,35 @@ on_monitors_changed (MetaMonitorManager *monitors,
compositor->outputs = meta_wayland_compositor_update_outputs (compositor, monitors);
}
static void
meta_wayland_output_init (MetaWaylandOutput *wayland_output)
{
}
static void
meta_wayland_output_finalize (GObject *object)
{
MetaWaylandOutput *wayland_output = META_WAYLAND_OUTPUT (object);
GList *resources;
/* Make sure the destructors don't mess with the list */
resources = wayland_output->resources;
wayland_output->resources = NULL;
wl_global_destroy (wayland_output->global);
g_list_free (resources);
G_OBJECT_CLASS (meta_wayland_output_parent_class)->finalize (object);
}
static void
meta_wayland_output_class_init (MetaWaylandOutputClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_wayland_output_finalize;
}
void
meta_wayland_outputs_init (MetaWaylandCompositor *compositor)
{

View File

@ -28,15 +28,34 @@
#include "backends/meta-monitor-manager-private.h"
#include "meta-wayland-private.h"
typedef struct
#define META_TYPE_WAYLAND_OUTPUT (meta_wayland_output_get_type ())
#define META_WAYLAND_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_WAYLAND_OUTPUT, MetaWaylandOutput))
#define META_WAYLAND_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_WAYLAND_OUTPUT, MetaWaylandOutputClass))
#define META_IS_WAYLAND_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_WAYLAND_OUTPUT))
#define META_IS_WAYLAND_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_WAYLAND_OUTPUT))
#define META_WAYLAND_OUTPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_WAYLAND_OUTPUT, MetaWaylandOutputClass))
typedef struct _MetaWaylandOutput MetaWaylandOutput;
typedef struct _MetaWaylandOutputClass MetaWaylandOutputClass;
struct _MetaWaylandOutput
{
GObject parent;
MetaMonitorInfo *monitor_info;
struct wl_global *global;
int x, y;
enum wl_output_transform transform;
GList *resources;
} MetaWaylandOutput;
};
struct _MetaWaylandOutputClass
{
GObjectClass parent_class;
};
GType meta_wayland_output_get_type (void) G_GNUC_CONST;
void meta_wayland_outputs_init (MetaWaylandCompositor *compositor);