Commit 1785b4ee authored by Guido Gunther's avatar Guido Gunther

monitor-manager: Export some of mutters DBus API

This is enough to see the monitors in the control panel with somewhat
correct mode information.

Future TODOs:

* use xdg-output protocol as well
* implement https://github.com/swaywm/wlr-protocols/issues/15
  so we can set rotation and scaling
parent 6c1cfc8d
subdir('wwan')
#subdir('battery')
subdir('monitor')
wayland_protos = dependency('wayland-protocols', version: '>=1.12')
wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir')
......@@ -48,6 +48,8 @@ phosh_sources = [
'lockscreen.h',
'lockshield.c',
'lockshield.h',
'monitor-manager.c',
'monitor-manager.h',
'panel.c',
'panel.h',
'phosh.c',
......@@ -58,6 +60,7 @@ phosh_sources = [
'wwaninfo.h',
phosh_resources,
phosh_wwan_sources,
phosh_monitor_sources,
wl_proto_sources,
]
......
This diff is collapsed.
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#pragma once
#include "monitor/phosh-display-dbus.h"
#include "monitor/monitor.h"
#include <glib-object.h>
#define PHOSH_TYPE_MONITOR_MANAGER (phosh_monitor_manager_get_type ())
G_DECLARE_FINAL_TYPE (PhoshMonitorManager, phosh_monitor_manager, PHOSH, MONITOR_MANAGER,
PhoshDisplayDbusOrgGnomeMutterDisplayConfigSkeleton)
PhoshMonitorManager * phosh_monitor_manager_new (void);
void phosh_monitor_manager_add_monitor (PhoshMonitorManager *self,
PhoshMonitor *monitor);
generated_monitor_sources = gnome.gdbus_codegen(
'phosh-display-dbus',
'org.gnome.Mutter.DisplayConfig.xml',
interface_prefix: 'org.gnome.Mutter.DisplayConfig.',
namespace: 'PhoshDisplayDbus',
)
phosh_monitor_sources = [
'monitor/monitor.c',
'monitor/monitor.h',
generated_monitor_sources,
]
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
/**
* A monitor. Currently we just wrap GDK but this will change once we have
* outputdevice handling in wlroots:
* https://github.com/swaywm/wlr-protocols/issues/15
*/
#define G_LOG_DOMAIN "phosh-monitor"
#include "monitor.h"
#include <gdk/gdkwayland.h>
enum {
PHOSH_MONITOR_PROP_0,
PHOSH_MONITOR_PROP_WL_OUTPUT,
PHOSH_MONITOR_PROP_LAST_PROP,
};
static GParamSpec *props[PHOSH_MONITOR_PROP_LAST_PROP];
G_DEFINE_TYPE (PhoshMonitor, phosh_monitor, G_TYPE_OBJECT)
static void
output_handle_geometry (void *data,
struct wl_output *wl_output,
int x,
int y,
int physical_width,
int physical_height,
int subpixel,
const char *make,
const char *model,
int32_t transform)
{
PhoshMonitor *self = PHOSH_MONITOR (data);
g_debug ("handle geometry output %p, position %d %d, size %dx%d, subpixel layout %d, vendor %s, "
"product %s, transform %d",
self, x, y, physical_width, physical_height, subpixel, make, model, transform);
self->x = x;
self->y = y;
self->width_mm = physical_width;
self->height_mm = physical_height;
self->subpixel = subpixel;
self->vendor = g_strdup (make);
self->product = g_strdup (model);
}
static void
output_handle_done (void *data,
struct wl_output *wl_output)
{
PhoshMonitor *self = PHOSH_MONITOR (data);
self->done = TRUE;
}
static void
output_handle_scale (void *data,
struct wl_output *wl_output,
int32_t scale)
{
PhoshMonitor *self = PHOSH_MONITOR (data);
self->scale = scale;
}
static void
output_handle_mode (void *data,
struct wl_output *wl_output,
uint32_t flags,
int width,
int height,
int refresh)
{
PhoshMonitor *self = PHOSH_MONITOR (data);
PhoshMonitorMode mode;
g_debug ("handle mode output %p, size %d %d, rate %d",
self, width, height, refresh);
mode.width = width;
mode.height = height;
mode.flags = flags;
mode.refresh = refresh;
g_array_append_val (self->modes, mode);
if (width > self->width)
self->width = width;
if (height > self->height)
self->height = height;
if ((flags & WL_OUTPUT_MODE_CURRENT) == 0)
self->current_mode = self->modes->len - 1;
}
static const struct wl_output_listener output_listener =
{
output_handle_geometry,
output_handle_mode,
output_handle_done,
output_handle_scale,
};
static void
phosh_monitor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PhoshMonitor *self = PHOSH_MONITOR (object);
switch (property_id) {
case PHOSH_MONITOR_PROP_WL_OUTPUT:
self->wl_output = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
phosh_monitor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PhoshMonitor *self = PHOSH_MONITOR (object);
switch (property_id) {
case PHOSH_MONITOR_PROP_WL_OUTPUT:
g_value_set_pointer (value, self->wl_output);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
phosh_monitor_dispose (GObject *object)
{
PhoshMonitor *self = PHOSH_MONITOR (object);
g_clear_pointer (&self->vendor, g_free);
g_clear_pointer (&self->product, g_free);
g_array_free (self->modes, TRUE);
self->modes = NULL;
G_OBJECT_CLASS (phosh_monitor_parent_class)->dispose (object);
}
static void
phosh_monitor_constructed (GObject *object)
{
PhoshMonitor *self = PHOSH_MONITOR (object);
wl_output_add_listener (self->wl_output, &output_listener, self);
}
static void
phosh_monitor_class_init (PhoshMonitorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = phosh_monitor_constructed;
object_class->dispose = phosh_monitor_dispose;
object_class->set_property = phosh_monitor_set_property;
object_class->get_property = phosh_monitor_get_property;
props[PHOSH_MONITOR_PROP_WL_OUTPUT] =
g_param_spec_pointer ("wl-output",
"wl-output",
"The wayland output associated with this monitor",
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PHOSH_MONITOR_PROP_LAST_PROP, props);
}
static void
phosh_monitor_init (PhoshMonitor *self)
{
self->scale = 1.0;
self->modes = g_array_new (FALSE, FALSE, sizeof(PhoshMonitorMode));
}
PhoshMonitor *
phosh_monitor_new_from_wl_output (gpointer wl_output)
{
return g_object_new (PHOSH_TYPE_MONITOR, "wl-output", wl_output, NULL);
}
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#pragma once
#include <glib-object.h>
#include <gdk/gdk.h>
typedef struct _PhoshMonitorMode
{
gint width, height;
gint refresh;
guint32 flags;
} PhoshMonitorMode;
#define PHOSH_TYPE_MONITOR (phosh_monitor_get_type ())
struct _PhoshMonitor {
GObject parent;
struct wl_output *wl_output;
gint x, y, width, height;
gint subpixel;
gint32 transform, scale;
gint width_mm;
gint height_mm;
char *vendor;
char *product;
GArray *modes;
guint current_mode;
gboolean done;
};
G_DECLARE_FINAL_TYPE (PhoshMonitor, phosh_monitor, PHOSH, MONITOR, GObject)
PhoshMonitor * phosh_monitor_new_from_wl_output (gpointer wl_output);
......@@ -28,9 +28,12 @@
#include "xdg-shell-client-protocol.h"
#include "phosh.h"
#include "monitor/monitor.h" /* FIXME: move upwards? */
#include "background.h"
#include "lockscreen.h"
#include "lockshield.h"
#include "monitor-manager.h"
#include "panel.h"
#include "favorites.h"
#include "settings.h"
......@@ -67,7 +70,7 @@ typedef struct
struct org_kde_kwin_idle *idle_manager;
struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
struct zwlr_input_inhibitor_v1 *input_inhibitor;
GPtrArray *outputs;
GPtrArray *outputs; /* FIXME: drop once monitors works */
struct wl_seat *wl_seat;
struct xdg_wm_base *xdg_wm_base;
......@@ -92,6 +95,9 @@ typedef struct
/* Settings menu */
struct popup *settings;
/* MonitorManager */
PhoshMonitorManager *monitor_manager;
} PhoshShellPrivate;
......@@ -626,6 +632,8 @@ registry_handle_global (void *data,
output = wl_registry_bind (registry, name,
&wl_output_interface, 1);
g_ptr_array_add (priv->outputs, output);
phosh_monitor_manager_add_monitor (priv->monitor_manager,
phosh_monitor_new_from_wl_output(output));
} else if (!strcmp (interface, "org_kde_kwin_idle")) {
priv->idle_manager = wl_registry_bind (registry,
name,
......@@ -751,6 +759,7 @@ phosh_shell_constructed (GObject *object)
g_error ("Failed to get display: %m\n");
}
priv->monitor_manager = phosh_monitor_manager_new ();
priv->registry = wl_display_get_registry (priv->display);
wl_registry_add_listener (priv->registry, &registry_listener, self);
......@@ -794,8 +803,9 @@ phosh_shell_class_init (PhoshShellClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = phosh_shell_constructed;
object_class->dispose = phosh_shell_dispose;
object_class->finalize = phosh_shell_finalize;
object_class->dispose = phosh_shell_dispose;
object_class->set_property = phosh_shell_set_property;
object_class->get_property = phosh_shell_get_property;
......
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