Commit 09e83439 authored by Guido Gunther's avatar Guido Gunther

Merge branch 'split-phosh' into 'master'

Split Wayland registry code into separate class

Closes #26

See merge request Librem5/phosh!84
parents 0a8c306b bac9b6c9
......@@ -130,7 +130,7 @@ background_draw_cb (PhoshBackground *self,
PhoshBackgroundPrivate *priv = phosh_background_get_instance_private (self);
gint x, y, width, height;
phosh_shell_get_usable_area (phosh(), &x, &y, &width, &height);
phosh_shell_get_usable_area (phosh_shell_get_default (), &x, &y, &width, &height);
gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, x, y);
cairo_paint (cr);
return TRUE;
......@@ -179,7 +179,7 @@ phosh_background_constructed (GObject *object)
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_widget_realize (GTK_WIDGET (self));
g_signal_connect_swapped (phosh(),
g_signal_connect_swapped (phosh_shell_get_default (),
"notify::rotation",
G_CALLBACK (rotation_notify_cb),
self);
......
......@@ -184,7 +184,7 @@ phosh_favorites_constructed (GObject *object)
G_OBJECT_CLASS (phosh_favorites_parent_class)->constructed (object);
/* window properties */
phosh_shell_get_usable_area (phosh(), NULL, NULL, &width, &height);
phosh_shell_get_usable_area (phosh_shell_get_default (), NULL, NULL, &width, &height);
gtk_window_set_title (GTK_WINDOW (self), "phosh favorites");
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_window_resize (GTK_WINDOW (self), width, height);
......
......@@ -76,7 +76,7 @@ keypad_update_labels (PhoshLockscreen *self)
len = strlen (number);
dots = pos = g_malloc0 (len * 3 + 1);
g_return_if_fail (dots);
for (int i; i < len; i++)
for (int i = 0; i < len; i++)
pos = g_stpcpy (pos, "●");
gtk_label_set_text (GTK_LABEL (priv->lbl_keypad), dots);
gtk_label_set_label (GTK_LABEL (priv->lbl_unlock_status), _("Enter PIN to unlock"));
......
......@@ -54,6 +54,9 @@ phosh_sources = [
'panel.c',
'panel.h',
'phosh.c',
'phosh.h',
'phosh-wayland.c',
'phosh-wayland.h',
'settings.c',
'settings.h',
'settings/brightness.c',
......
......@@ -12,6 +12,7 @@
#include "monitor/monitor.h"
#include "gamma-control-client-protocol.h"
#include "phosh-wayland.h"
#include "phosh.h"
#include <gdk/gdkwayland.h>
......@@ -238,7 +239,8 @@ phosh_monitor_manager_handle_get_crtc_gamma (
return TRUE;
}
gamma_control_manager = phosh_shell_get_wl_gamma_control_manager ();
gamma_control_manager = phosh_wayland_get_gamma_control_manager (
phosh_wayland_get_default ());
if (gamma_control_manager == NULL) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_NOT_SUPPORTED,
......@@ -294,7 +296,8 @@ phosh_monitor_manager_handle_set_crtc_gamma (
return TRUE;
}
gamma_control_manager = phosh_shell_get_wl_gamma_control_manager ();
gamma_control_manager = phosh_wayland_get_gamma_control_manager (
phosh_wayland_get_default ());
if (!gamma_control_manager) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_NOT_SUPPORTED,
......
......@@ -19,5 +19,3 @@ void phosh_monitor_manager_add_monitor (PhoshMoni
PhoshMonitor * phosh_monitor_manager_get_monitor (PhoshMonitorManager *self,
guint monitor);
guint phosh_monitor_manager_get_num_monitors (PhoshMonitorManager *self);
void phosh_monitor_manager_set_gamma_control_manager (PhoshMonitorManager *self,
gpointer *gamma);
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define G_LOG_DOMAIN "phosh-wayland"
#include "config.h"
#include "phosh-wayland.h"
#include <gdk/gdkwayland.h>
/**
* SECTION:phosh-wayland
* @short_description: A wayland registry listener
* @Title: PhoshWayland
*
* The #PhoshWayland singleton is responsible for listening to wayland
* registry events registering the objects that show up there to make
* them available to Phosh's other classes.
*/
typedef struct {
struct wl_display *display;
struct wl_registry *registry;
struct phosh_private *phosh_private;
struct zwlr_layer_shell_v1 *layer_shell;
struct org_kde_kwin_idle *idle_manager;
struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
struct gamma_control_manager *gamma_control_manager;
struct wl_seat *wl_seat;
struct xdg_wm_base *xdg_wm_base;
GPtrArray *wl_outputs;
} PhoshWaylandPrivate;
typedef struct _PhoshWayland {
GObject parent;
} PhoshWayland;
G_DEFINE_TYPE_WITH_PRIVATE (PhoshWayland, phosh_wayland, G_TYPE_OBJECT)
static void
registry_handle_global (void *data,
struct wl_registry *registry,
uint32_t name,
const char *interface,
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 (
registry,
name,
&phosh_private_interface,
1);
} else if (!strcmp (interface, zwlr_layer_shell_v1_interface.name)) {
priv->layer_shell = wl_registry_bind (
registry,
name,
&zwlr_layer_shell_v1_interface,
1);
} else if (!strcmp (interface, "wl_output")) {
output = wl_registry_bind (
registry,
name,
&wl_output_interface, 2);
g_ptr_array_add (priv->wl_outputs, output);
} else if (!strcmp (interface, "org_kde_kwin_idle")) {
priv->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(
registry, name, &wl_seat_interface,
1);
} else if (!strcmp(interface, zwlr_input_inhibit_manager_v1_interface.name)) {
priv->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(
registry,
name,
&xdg_wm_base_interface,
1);
} else if (!strcmp(interface, gamma_control_manager_interface.name)) {
priv->gamma_control_manager = wl_registry_bind(
registry,
name,
&gamma_control_manager_interface,
1);
}
}
static void
registry_handle_global_remove (void *data,
struct wl_registry *registry,
uint32_t name)
{
// TODO
}
static const struct wl_registry_listener registry_listener = {
registry_handle_global,
registry_handle_global_remove
};
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;
G_OBJECT_CLASS (phosh_wayland_parent_class)->constructed (object);
gdk_set_allowed_backends ("wayland");
gdk_display = gdk_display_get_default ();
priv->display = gdk_wayland_display_get_wl_display (gdk_display);
if (priv->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);
/* Wait until we have been notified about the wayland globals we require */
num_outputs = priv->wl_outputs->len;
if (!num_outputs || !priv->layer_shell || !priv->idle_manager ||
!priv->input_inhibit_manager || !priv->phosh_private || !priv->xdg_wm_base)
wl_display_roundtrip (priv->display);
num_outputs = priv->wl_outputs->len;
if (!num_outputs || !priv->layer_shell || !priv->idle_manager ||
!priv->input_inhibit_manager || !priv->xdg_wm_base) {
g_error ("Could not find needed globals\n"
"outputs: %d, layer_shell: %p, seat: %p, "
"inhibit: %p, xdg_wm: %p\n",
num_outputs, priv->layer_shell, priv->idle_manager,
priv->input_inhibit_manager, priv->xdg_wm_base);
}
if (!priv->phosh_private) {
g_info ("Could not find phosh private interface, disabling some features\n");
}
}
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_ptr_array_unref);
}
static void
phosh_wayland_class_init (PhoshWaylandClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = phosh_wayland_constructed;
object_class->dispose = phosh_wayland_dispose;
}
static void
phosh_wayland_init (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
priv->wl_outputs = g_ptr_array_new ();
}
PhoshWayland *
phosh_wayland_get_default ()
{
static PhoshWayland *instance;
if (instance == NULL) {
instance = g_object_new (PHOSH_TYPE_WAYLAND, NULL);
g_object_add_weak_pointer (G_OBJECT (instance), (gpointer *)&instance);
}
return instance;
}
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;
}
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;
}
struct wl_seat*
phosh_wayland_get_wl_seat (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->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;
}
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;
}
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;
}
struct phosh_private*
phosh_wayland_get_phosh_private (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->phosh_private;
}
GPtrArray*
phosh_wayland_get_wl_outputs (PhoshWayland *self)
{
PhoshWaylandPrivate *priv = phosh_wayland_get_instance_private (self);
return priv->wl_outputs;
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#pragma once
#include "idle-client-protocol.h"
#include "phosh-private-client-protocol.h"
#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "gamma-control-client-protocol.h"
#include <glib-object.h>
#define PHOSH_TYPE_WAYLAND phosh_wayland_get_type()
G_DECLARE_FINAL_TYPE (PhoshWayland, phosh_wayland, PHOSH, WAYLAND, GObject)
PhoshWayland *phosh_wayland_get_default (void);
GPtrArray *phosh_wayland_get_wl_outputs (PhoshWayland *self);
struct gamma_control_manager *phosh_wayland_get_gamma_control_manager (PhoshWayland *self);
struct org_kde_kwin_idle *phosh_wayland_get_org_kde_kwin_idle (PhoshWayland *self);
struct phosh_private *phosh_wayland_get_phosh_private (PhoshWayland *self);
struct wl_seat *phosh_wayland_get_wl_seat (PhoshWayland *self);
struct xdg_wm_base *phosh_wayland_get_xdg_wm_base (PhoshWayland *self);
struct zwlr_input_inhibit_manager_v1 *phosh_wayland_get_zwlr_input_inhibit_manager_v1 (PhoshWayland *self);
struct zwlr_layer_shell_v1 *phosh_wayland_get_zwlr_layer_shell_v1 (PhoshWayland *self);
This diff is collapsed.
......@@ -16,7 +16,7 @@
G_DECLARE_FINAL_TYPE (PhoshShell, phosh_shell, PHOSH, SHELL, GObject)
PhoshShell * phosh (void);
PhoshShell *phosh_shell_get_default (void);
void phosh_shell_rotate_display (PhoshShell *self, guint degrees);
int phosh_shell_get_rotation (PhoshShell *self);
void phosh_shell_get_usable_area (PhoshShell *self,
......@@ -27,9 +27,5 @@ void phosh_shell_get_usable_area (PhoshShell *self,
void phosh_shell_set_locked (PhoshShell *self, gboolean locked);
void phosh_shell_lock (PhoshShell *self);
void phosh_shell_unlock (PhoshShell *self);
PhoshMonitor *phosh_shell_get_primary_monitor ();
/* Phosh keeps track of the wayland globals */
gpointer phosh_shell_get_wl_layer_shell ();
gpointer phosh_shell_get_wl_gamma_control_manager ();
PhoshMonitor *phosh_shell_get_primary_monitor (PhoshShell *self);
#endif /* PHOSH_H */
......@@ -66,7 +66,7 @@ brightness_changed_cb (GtkAdjustment *adj_brightness, gpointer *unused)
static void
rotation_changed_cb (GtkSwitch *btn, GParamSpec *pspec, PhoshSettings *self)
{
PhoshShell *shell = phosh();
PhoshShell *shell = phosh_shell_get_default ();
gboolean rotate;
rotate = gtk_switch_get_active(btn);
......@@ -95,7 +95,7 @@ settings_clicked_cb (PhoshSettings *self, gpointer *unused)
static void
lock_screen_clicked_cb (PhoshSettings *self, gpointer *unused)
{
phosh_shell_lock (phosh());
phosh_shell_lock (phosh_shell_get_default ());
g_signal_emit (self, signals[SETTING_DONE], 0);
}
......@@ -126,7 +126,7 @@ phosh_settings_constructed (GObject *object)
priv->adj_volume = gtk_adjustment_new (0, 0, 100, 1, 10, 10);
gtk_range_set_adjustment (GTK_RANGE (priv->scale_volume), priv->adj_volume);
if (phosh_shell_get_rotation (phosh()))
if (phosh_shell_get_rotation (phosh_shell_get_default ()))
gtk_switch_set_active (GTK_SWITCH (priv->btn_rotation), TRUE);
g_signal_connect (priv->btn_rotation,
"notify::active",
......
......@@ -63,7 +63,7 @@ icon_to_pixbuf (PhoshWWanInfo *self,
GtkIconTheme *theme)
{
PhoshWWanInfoPrivate *priv = phosh_wwan_info_get_instance_private (self);
g_autoptr(GtkIconInfo) info;
g_autoptr(GtkIconInfo) info = NULL;
GdkPixbuf *pixbuf;
GError *error = NULL;
......@@ -99,7 +99,7 @@ pixbuf_overlay_access_tec (PhoshWWanInfo *self,
PangoFontDescription *desc;
gint tw = 0, th = 0, scale;
guint width, height;
g_autofree char *font;
g_autofree char *font = NULL;
width = gdk_pixbuf_get_width (source);
height = gdk_pixbuf_get_height (source);
......@@ -156,7 +156,6 @@ update_icon_data(PhoshWWanInfo *self, PhoshWWanMM *wwan, gpointer unused)
PhoshWWanInfoPrivate *priv;
guint quality;
GtkIconTheme *icon_theme;
//g_autoptr(GIcon) icon = NULL;
g_autoptr(GdkPixbuf) src = NULL, dest = NULL;
g_autofree gchar *icon_name = NULL;
const char *access_tec;
......
......@@ -3,7 +3,7 @@
#include <glib.h>
gpointer
phosh ()
phosh_shell_get_default ()
{
return NULL;
}
......
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