Commit d0be6713 authored by Guido Gunther's avatar Guido Gunther Committed by Sebastian Krzyszkowiak
Browse files

wayland: Drop priv



for less code. And rather check for the right type in public methods
instead.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 7810e969
Pipeline #59923 passed with stages
in 54 minutes and 28 seconds
......@@ -30,7 +30,9 @@ enum {
};
static GParamSpec *props[PHOSH_WAYLAND_PROP_LAST_PROP];
typedef struct {
struct _PhoshWayland {
GObject parent;
struct gamma_control_manager *gamma_control_manager;
struct org_kde_kwin_idle *idle_manager;
struct phosh_private *phosh_private;
......@@ -46,15 +48,9 @@ typedef struct {
struct zxdg_output_manager_v1 *zxdg_output_manager_v1;
struct wl_shm *wl_shm;
GHashTable *wl_outputs;
} PhoshWaylandPrivate;
typedef struct _PhoshWayland {
GObject parent;
} PhoshWayland;
};
G_DEFINE_TYPE_WITH_PRIVATE (PhoshWayland, phosh_wayland, G_TYPE_OBJECT)
G_DEFINE_TYPE (PhoshWayland, phosh_wayland, G_TYPE_OBJECT)
static void
......@@ -65,17 +61,16 @@ registry_handle_global (void *data,
uint32_t version)
{
PhoshWayland *self = data;
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
struct wl_output *output;
if (!strcmp (interface, "phosh_private")) {
priv->phosh_private = wl_registry_bind (
self->phosh_private = wl_registry_bind (
registry,
name,
&phosh_private_interface,
MIN(5, version));
} else if (!strcmp (interface, zwlr_layer_shell_v1_interface.name)) {
priv->layer_shell = wl_registry_bind (
self->layer_shell = wl_registry_bind (
registry,
name,
&zwlr_layer_shell_v1_interface,
......@@ -86,60 +81,60 @@ registry_handle_global (void *data,
name,
&wl_output_interface, 2);
g_debug ("Got new output %p", output);
g_hash_table_insert (priv->wl_outputs, GINT_TO_POINTER (name), output);
g_hash_table_insert (self->wl_outputs, GINT_TO_POINTER (name), output);
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_WAYLAND_PROP_WL_OUTPUTS]);
} else if (!strcmp (interface, "org_kde_kwin_idle")) {
priv->idle_manager = wl_registry_bind (
self->idle_manager = wl_registry_bind (
registry,
name,
&org_kde_kwin_idle_interface,
1);
} else if (!strcmp(interface, "wl_seat")) {
priv->wl_seat = wl_registry_bind(
self->wl_seat = wl_registry_bind(
registry, name, &wl_seat_interface,
1);
} else if (!strcmp(interface, "wl_shm")) {
priv->wl_shm = wl_registry_bind(
self->wl_shm = wl_registry_bind(
registry, name, &wl_shm_interface,
1);
} else if (!strcmp(interface, zwlr_input_inhibit_manager_v1_interface.name)) {
priv->input_inhibit_manager = wl_registry_bind(
self->input_inhibit_manager = wl_registry_bind(
registry,
name,
&zwlr_input_inhibit_manager_v1_interface,
1);
} else if (!strcmp(interface, xdg_wm_base_interface.name)) {
priv->xdg_wm_base = wl_registry_bind(
self->xdg_wm_base = wl_registry_bind(
registry,
name,
&xdg_wm_base_interface,
1);
} else if (!strcmp(interface, gamma_control_manager_interface.name)) {
priv->gamma_control_manager = wl_registry_bind(
self->gamma_control_manager = wl_registry_bind(
registry,
name,
&gamma_control_manager_interface,
1);
} else if (!strcmp (interface, zxdg_output_manager_v1_interface.name)) {
priv->zxdg_output_manager_v1 = wl_registry_bind(
self->zxdg_output_manager_v1 = wl_registry_bind(
registry,
name,
&zxdg_output_manager_v1_interface,
2);
} else if (!strcmp (interface, zwlr_output_manager_v1_interface.name)) {
priv->zwlr_output_manager_v1 = wl_registry_bind(
self->zwlr_output_manager_v1 = wl_registry_bind(
registry,
name,
&zwlr_output_manager_v1_interface,
1);
} else if (!strcmp (interface, zwlr_output_power_manager_v1_interface.name)) {
priv->zwlr_output_power_manager_v1 = wl_registry_bind(
self->zwlr_output_power_manager_v1 = wl_registry_bind(
registry,
name,
&zwlr_output_power_manager_v1_interface,
1);
} else if (!strcmp (interface, zwlr_foreign_toplevel_manager_v1_interface.name)) {
priv->zwlr_foreign_toplevel_manager_v1 = wl_registry_bind(
self->zwlr_foreign_toplevel_manager_v1 = wl_registry_bind(
registry,
name,
&zwlr_foreign_toplevel_manager_v1_interface,
......@@ -154,13 +149,12 @@ registry_handle_global_remove (void *data,
uint32_t name)
{
PhoshWayland *self = data;
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
struct wl_output *wl_output;
wl_output = g_hash_table_lookup (priv->wl_outputs, GINT_TO_POINTER (name));
wl_output = g_hash_table_lookup (self->wl_outputs, GINT_TO_POINTER (name));
if (wl_output) {
g_debug ("Output %d removed", name);
g_hash_table_remove (priv->wl_outputs, GINT_TO_POINTER (name));
g_hash_table_remove (self->wl_outputs, GINT_TO_POINTER (name));
wl_output_destroy (wl_output);
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_WAYLAND_PROP_WL_OUTPUTS]);
} else {
......@@ -182,11 +176,10 @@ phosh_wayland_get_property (GObject *object,
GParamSpec *pspec)
{
PhoshWayland *self = PHOSH_WAYLAND (object);
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private(self);
switch (property_id) {
case PHOSH_WAYLAND_PROP_WL_OUTPUTS:
g_value_set_boxed (value, priv->wl_outputs);
g_value_set_boxed (value, self->wl_outputs);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
......@@ -199,7 +192,6 @@ static void
phosh_wayland_constructed (GObject *object)
{
PhoshWayland *self = PHOSH_WAYLAND (object);
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
guint num_outputs;
GdkDisplay *gdk_display;
......@@ -207,34 +199,34 @@ phosh_wayland_constructed (GObject *object)
gdk_set_allowed_backends ("wayland");
gdk_display = gdk_display_get_default ();
priv->display = gdk_wayland_display_get_wl_display (gdk_display);
self->display = gdk_wayland_display_get_wl_display (gdk_display);
if (priv->display == NULL) {
if (self->display == NULL) {
g_error ("Failed to get display: %m\n");
}
priv->registry = wl_display_get_registry (priv->display);
wl_registry_add_listener (priv->registry, &registry_listener, self);
self->registry = wl_display_get_registry (self->display);
wl_registry_add_listener (self->registry, &registry_listener, self);
/* Wait until we have been notified about the wayland globals we require */
phosh_wayland_roundtrip (self);
num_outputs = g_hash_table_size(priv->wl_outputs);
if (!num_outputs || !priv->layer_shell || !priv->idle_manager ||
!priv->input_inhibit_manager || !priv->xdg_wm_base ||
!priv->zxdg_output_manager_v1) {
num_outputs = g_hash_table_size(self->wl_outputs);
if (!num_outputs || !self->layer_shell || !self->idle_manager ||
!self->input_inhibit_manager || !self->xdg_wm_base ||
!self->zxdg_output_manager_v1) {
g_error ("Could not find needed globals\n"
"outputs: %d, layer_shell: %p, idle_manager: %p, "
"inhibit: %p, xdg_wm: %p, "
"xdg_output: %p, wlr_output_manager: %p, "
"wlr_foreign_toplevel_manager: %p"
"\n",
num_outputs, priv->layer_shell, priv->idle_manager,
priv->input_inhibit_manager, priv->xdg_wm_base,
priv->zxdg_output_manager_v1,
priv->zwlr_output_manager_v1,
priv->zwlr_foreign_toplevel_manager_v1);
num_outputs, self->layer_shell, self->idle_manager,
self->input_inhibit_manager, self->xdg_wm_base,
self->zxdg_output_manager_v1,
self->zwlr_output_manager_v1,
self->zwlr_foreign_toplevel_manager_v1);
}
if (!priv->phosh_private) {
if (!self->phosh_private) {
g_info ("Could not find phosh private interface, disabling some features");
}
}
......@@ -244,9 +236,8 @@ static void
phosh_wayland_dispose (GObject *object)
{
PhoshWayland *self = PHOSH_WAYLAND (object);
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
g_clear_pointer (&priv->wl_outputs, g_hash_table_destroy);
g_clear_pointer (&self->wl_outputs, g_hash_table_destroy);
G_OBJECT_CLASS (phosh_wayland_parent_class)->dispose (object);
}
......@@ -274,8 +265,7 @@ phosh_wayland_class_init (PhoshWaylandClass *klass)
static void
phosh_wayland_init (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
priv->wl_outputs = g_hash_table_new (g_direct_hash, g_direct_equal);
self->wl_outputs = g_hash_table_new (g_direct_hash, g_direct_equal);
}
......@@ -295,102 +285,106 @@ phosh_wayland_get_default (void)
struct zwlr_layer_shell_v1 *
phosh_wayland_get_zwlr_layer_shell_v1 (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->layer_shell;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->layer_shell;
}
struct gamma_control_manager*
phosh_wayland_get_gamma_control_manager (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->gamma_control_manager;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->gamma_control_manager;
}
struct wl_seat*
phosh_wayland_get_wl_seat (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->wl_seat;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->wl_seat;
}
struct xdg_wm_base*
phosh_wayland_get_xdg_wm_base (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->xdg_wm_base;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->xdg_wm_base;
}
struct zwlr_input_inhibit_manager_v1*
phosh_wayland_get_zwlr_input_inhibit_manager_v1 (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->input_inhibit_manager;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->input_inhibit_manager;
}
struct org_kde_kwin_idle*
phosh_wayland_get_org_kde_kwin_idle (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->idle_manager;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->idle_manager;
}
struct phosh_private*
phosh_wayland_get_phosh_private (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->phosh_private;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->phosh_private;
}
struct wl_shm*
phosh_wayland_get_wl_shm (PhoshWayland *self)
{
PhoshWaylandPrivate *priv;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
priv = phosh_wayland_get_instance_private (self);
return priv->wl_shm;
return self->wl_shm;
}
struct zxdg_output_manager_v1*
phosh_wayland_get_zxdg_output_manager_v1 (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->zxdg_output_manager_v1;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->zxdg_output_manager_v1;
}
struct zwlr_output_manager_v1*
phosh_wayland_get_zwlr_output_manager_v1 (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->zwlr_output_manager_v1;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->zwlr_output_manager_v1;
}
struct zwlr_output_power_manager_v1*
phosh_wayland_get_zwlr_output_power_manager_v1 (PhoshWayland *self)
{
PhoshWaylandPrivate *priv;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
priv = phosh_wayland_get_instance_private (self);
return priv->zwlr_output_power_manager_v1;
return self->zwlr_output_power_manager_v1;
}
struct zwlr_foreign_toplevel_manager_v1*
phosh_wayland_get_zwlr_foreign_toplevel_manager_v1 (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->zwlr_foreign_toplevel_manager_v1;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->zwlr_foreign_toplevel_manager_v1;
}
/**
......@@ -403,21 +397,20 @@ phosh_wayland_get_zwlr_foreign_toplevel_manager_v1 (PhoshWayland *self)
GHashTable *
phosh_wayland_get_wl_outputs (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->wl_outputs;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->wl_outputs;
}
gboolean
phosh_wayland_has_wl_output (PhoshWayland *self, struct wl_output *wl_output)
{
PhoshWaylandPrivate *priv;
GHashTableIter iter;
gpointer key, value;
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), FALSE);
priv = phosh_wayland_get_instance_private (self);
g_hash_table_iter_init (&iter, priv->wl_outputs);
g_hash_table_iter_init (&iter, self->wl_outputs);
while (g_hash_table_iter_next (&iter, &key, &value)) {
if ((struct wl_output *) value == wl_output)
return TRUE;
......@@ -429,6 +422,7 @@ phosh_wayland_has_wl_output (PhoshWayland *self, struct wl_output *wl_output)
void
phosh_wayland_roundtrip (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
wl_display_roundtrip(priv->display);
g_return_if_fail (PHOSH_IS_WAYLAND (self));
wl_display_roundtrip(self->display);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment