mirror of
https://github.com/zoriya/astal.git
synced 2026-06-05 10:59:34 +00:00
add icons
This commit is contained in:
@@ -16,6 +16,7 @@ typedef enum {
|
||||
ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER,
|
||||
ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER,
|
||||
ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM,
|
||||
ASTAL_WP_MEDIA_CLASS_AUDIO_DEVICE,
|
||||
} AstalWpMediaClass;
|
||||
|
||||
void astal_wp_endpoint_update_volume(AstalWpEndpoint *self);
|
||||
@@ -29,6 +30,8 @@ gboolean astal_wp_endpoint_get_mute(AstalWpEndpoint *self);
|
||||
gdouble astal_wp_endpoint_get_volume(AstalWpEndpoint *self);
|
||||
const gchar *astal_wp_endpoint_get_description(AstalWpEndpoint *self);
|
||||
void astal_wp_endpoint_set_is_default(AstalWpEndpoint *self, gboolean is_default);
|
||||
const gchar *astal_wp_endpoint_get_name(AstalWpEndpoint *self);
|
||||
const gchar *astal_wp_endpoint_get_icon_name(AstalWpEndpoint *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -332,6 +332,8 @@ static void astal_wp_audio_object_added(AstalWpAudio *self, gpointer object) {
|
||||
g_signal_emit_by_name(self, "recorder-added", endpoint);
|
||||
g_object_notify(G_OBJECT(self), "recorders");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_signal_emit_by_name(self, "changed");
|
||||
@@ -356,6 +358,8 @@ static void astal_wp_audio_object_removed(AstalWpAudio *self, gpointer object) {
|
||||
g_signal_emit_by_name(self, "recorder-removed", endpoint);
|
||||
g_object_notify(G_OBJECT(self), "recorders");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_signal_emit_by_name(self, "changed");
|
||||
|
||||
+2
-4
@@ -1,8 +1,7 @@
|
||||
#include "device-private.h"
|
||||
|
||||
#include <wp/wp.h>
|
||||
#include "profile.h"
|
||||
|
||||
#include "device-private.h"
|
||||
#include "profile.h"
|
||||
|
||||
struct _AstalWpDevice {
|
||||
GObject parent_instance;
|
||||
@@ -186,7 +185,6 @@ static void astal_wp_device_update_properties(AstalWpDevice *self) {
|
||||
AstalWpDevicePrivate *priv = astal_wp_device_get_instance_private(self);
|
||||
if (priv->device == NULL) return;
|
||||
self->id = wp_proxy_get_bound_id(WP_PROXY(priv->device));
|
||||
|
||||
const gchar *description =
|
||||
wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->device), "device.description");
|
||||
if (description == NULL) {
|
||||
|
||||
+66
-3
@@ -1,7 +1,12 @@
|
||||
#include "endpoint.h"
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "device.h"
|
||||
#include "endpoint-private.h"
|
||||
#include "glib.h"
|
||||
#include "wp.h"
|
||||
#include "wp/proxy-interfaces.h"
|
||||
|
||||
struct _AstalWpEndpoint {
|
||||
GObject parent_instance;
|
||||
@@ -10,8 +15,11 @@ struct _AstalWpEndpoint {
|
||||
gdouble volume;
|
||||
gboolean mute;
|
||||
gchar *description;
|
||||
gchar *name;
|
||||
AstalWpMediaClass type;
|
||||
gboolean is_default;
|
||||
|
||||
gchar *icon;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -40,8 +48,10 @@ typedef enum {
|
||||
ASTAL_WP_ENDPOINT_PROP_VOLUME,
|
||||
ASTAL_WP_ENDPOINT_PROP_MUTE,
|
||||
ASTAL_WP_ENDPOINT_PROP_DESCRIPTION,
|
||||
ASTAL_WP_ENDPOINT_PROP_NAME,
|
||||
ASTAL_WP_ENDPOINT_PROP_MEDIA_CLASS,
|
||||
ASTAL_WP_ENDPOINT_PROP_DEFAULT,
|
||||
ASTAL_WP_ENDPOINT_PROP_ICON,
|
||||
ASTAL_WP_ENDPOINT_N_PROPERTIES,
|
||||
} AstalWpEndpointProperties;
|
||||
|
||||
@@ -116,6 +126,10 @@ gdouble astal_wp_endpoint_get_volume(AstalWpEndpoint *self) { return self->volum
|
||||
|
||||
const gchar *astal_wp_endpoint_get_description(AstalWpEndpoint *self) { return self->description; }
|
||||
|
||||
const gchar *astal_wp_endpoint_get_name(AstalWpEndpoint *self) { return self->name; }
|
||||
|
||||
const gchar *astal_wp_endpoint_get_icon(AstalWpEndpoint *self) { return self->icon; }
|
||||
|
||||
gboolean astal_wp_endpoint_get_is_default(AstalWpEndpoint *self) { return self->is_default; }
|
||||
|
||||
void astal_wp_endpoint_set_is_default(AstalWpEndpoint *self, gboolean is_default) {
|
||||
@@ -148,6 +162,12 @@ static void astal_wp_endpoint_get_property(GObject *object, guint property_id, G
|
||||
case ASTAL_WP_ENDPOINT_PROP_DESCRIPTION:
|
||||
g_value_set_string(value, self->description);
|
||||
break;
|
||||
case ASTAL_WP_ENDPOINT_PROP_NAME:
|
||||
g_value_set_string(value, self->name);
|
||||
break;
|
||||
case ASTAL_WP_ENDPOINT_PROP_ICON:
|
||||
g_value_set_string(value, self->icon);
|
||||
break;
|
||||
case ASTAL_WP_ENDPOINT_PROP_MEDIA_CLASS:
|
||||
g_value_set_enum(value, self->type);
|
||||
break;
|
||||
@@ -195,12 +215,14 @@ static void astal_wp_endpoint_update_properties(AstalWpEndpoint *self) {
|
||||
if (description == NULL) {
|
||||
description = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "node.name");
|
||||
}
|
||||
if (description == NULL) {
|
||||
description = "unknown";
|
||||
}
|
||||
g_free(self->description);
|
||||
self->description = g_strdup(description);
|
||||
|
||||
const gchar *name =
|
||||
wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.name");
|
||||
g_free(self->name);
|
||||
self->name = g_strdup(name);
|
||||
|
||||
const gchar *type =
|
||||
wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.class");
|
||||
GEnumClass *enum_class = g_type_class_ref(ASTAL_WP_TYPE_MEDIA_CLASS);
|
||||
@@ -208,8 +230,43 @@ static void astal_wp_endpoint_update_properties(AstalWpEndpoint *self) {
|
||||
self->type = g_enum_get_value_by_nick(enum_class, type)->value;
|
||||
g_type_class_unref(enum_class);
|
||||
|
||||
const gchar *icon = NULL;
|
||||
switch (self->type) {
|
||||
case ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER:
|
||||
case ASTAL_WP_MEDIA_CLASS_AUDIO_MICROPHONE:
|
||||
const gchar *dev =
|
||||
wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "device.id");
|
||||
guint device_id = g_ascii_strtoull(dev, NULL, 10);
|
||||
AstalWpDevice *device = astal_wp_wp_get_device(astal_wp_wp_get_default(), device_id);
|
||||
icon = astal_wp_device_get_icon(device);
|
||||
if (icon == NULL) {
|
||||
icon = self->type == ASTAL_WP_MEDIA_CLASS_AUDIO_SPEAKER
|
||||
? "audio-card-symbolic"
|
||||
: "audio-input-microphone-symbolic";
|
||||
}
|
||||
break;
|
||||
case ASTAL_WP_MEDIA_CLASS_AUDIO_STREAM:
|
||||
case ASTAL_WP_MEDIA_CLASS_AUDIO_RECORDER:
|
||||
icon =
|
||||
wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node), "media.icon-name");
|
||||
if (icon == NULL)
|
||||
icon = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node),
|
||||
"window.icon-name");
|
||||
if (icon == NULL)
|
||||
icon = wp_pipewire_object_get_property(WP_PIPEWIRE_OBJECT(priv->node),
|
||||
"application.icon-name");
|
||||
if (icon == NULL) icon = "application-x-executable-symbolic";
|
||||
break;
|
||||
default:
|
||||
icon = "audio-card-symbolc";
|
||||
}
|
||||
g_free(self->icon);
|
||||
self->icon = g_strdup(icon);
|
||||
|
||||
g_object_notify(G_OBJECT(self), "id");
|
||||
g_object_notify(G_OBJECT(self), "description");
|
||||
g_object_notify(G_OBJECT(self), "name");
|
||||
g_object_notify(G_OBJECT(self), "icon");
|
||||
g_object_notify(G_OBJECT(self), "type");
|
||||
g_signal_emit_by_name(self, "changed");
|
||||
}
|
||||
@@ -310,6 +367,7 @@ static void astal_wp_endpoint_init(AstalWpEndpoint *self) {
|
||||
self->volume = 0;
|
||||
self->mute = TRUE;
|
||||
self->description = NULL;
|
||||
self->name = NULL;
|
||||
}
|
||||
|
||||
static void astal_wp_endpoint_dispose(GObject *object) {
|
||||
@@ -327,6 +385,7 @@ static void astal_wp_endpoint_dispose(GObject *object) {
|
||||
static void astal_wp_endpoint_finalize(GObject *object) {
|
||||
AstalWpEndpoint *self = ASTAL_WP_ENDPOINT(object);
|
||||
g_free(self->description);
|
||||
g_free(self->name);
|
||||
}
|
||||
|
||||
static void astal_wp_endpoint_class_init(AstalWpEndpointClass *class) {
|
||||
@@ -344,6 +403,10 @@ static void astal_wp_endpoint_class_init(AstalWpEndpointClass *class) {
|
||||
g_param_spec_boolean("mute", "mute", "mute", TRUE, G_PARAM_READWRITE);
|
||||
astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_DESCRIPTION] =
|
||||
g_param_spec_string("description", "description", "description", NULL, G_PARAM_READABLE);
|
||||
astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_NAME] =
|
||||
g_param_spec_string("name", "name", "name", NULL, G_PARAM_READABLE);
|
||||
astal_wp_endpoint_properties[ASTAL_WP_ENDPOINT_PROP_ICON] =
|
||||
g_param_spec_string("icon", "icon", "icon", NULL, G_PARAM_READABLE);
|
||||
/**
|
||||
* AstalWpEndpoint:media-class: (type AstalWpMediaClass)
|
||||
*
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
#include <wp/wp.h>
|
||||
#include "profile.h"
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
struct _AstalWpProfile {
|
||||
GObject parent_instance;
|
||||
|
||||
|
||||
+2
-2
@@ -182,8 +182,8 @@ static void astal_wp_wp_object_added(AstalWpWp *self, gpointer object) {
|
||||
} else if (WP_IS_DEVICE(object)) {
|
||||
WpDevice *node = WP_DEVICE(object);
|
||||
AstalWpDevice *device = astal_wp_device_create(node);
|
||||
g_hash_table_insert(priv->devices,
|
||||
GUINT_TO_POINTER(wp_proxy_get_bound_id(WP_PROXY(device))), device);
|
||||
g_hash_table_insert(priv->devices, GUINT_TO_POINTER(wp_proxy_get_bound_id(WP_PROXY(node))),
|
||||
device);
|
||||
g_signal_emit_by_name(self, "device-added", device);
|
||||
g_object_notify(G_OBJECT(self), "devices");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user