mirror of
https://gitlab.gnome.org/GNOME/libmks.git
synced 2024-12-22 13:45:21 +00:00
lib: add MksSpeaker
This isn't attached to AudioOut interface yet, but starts on the API to be defined for that.
This commit is contained in:
parent
af901239d0
commit
39a0bb2658
@ -8,6 +8,7 @@ libmks_sources = [
|
||||
'mks-screen.c',
|
||||
'mks-screen-attributes.c',
|
||||
'mks-session.c',
|
||||
'mks-speaker.c',
|
||||
]
|
||||
|
||||
libmks_headers = [
|
||||
@ -20,6 +21,7 @@ libmks_headers = [
|
||||
'mks-screen.h',
|
||||
'mks-screen-attributes.h',
|
||||
'mks-session.h',
|
||||
'mks-speaker.h',
|
||||
'mks-types.h',
|
||||
]
|
||||
|
||||
|
158
lib/mks-speaker.c
Normal file
158
lib/mks-speaker.c
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* mks-speaker.c
|
||||
*
|
||||
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mks-device-private.h"
|
||||
#include "mks-qemu.h"
|
||||
#include "mks-speaker.h"
|
||||
|
||||
struct _MksSpeaker
|
||||
{
|
||||
MksDevice parent_instance;
|
||||
guint muted : 1;
|
||||
};
|
||||
|
||||
struct _MksSpeakerClass
|
||||
{
|
||||
MksDeviceClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (MksSpeaker, mks_speaker, MKS_TYPE_DEVICE)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_MUTED,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
mks_speaker_dispose (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (mks_speaker_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mks_speaker_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MksSpeaker *self = MKS_SPEAKER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_MUTED:
|
||||
g_value_set_boolean (value, mks_speaker_get_muted (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mks_speaker_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MksSpeaker *self = MKS_SPEAKER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_MUTED:
|
||||
mks_speaker_set_muted (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mks_speaker_class_init (MksSpeakerClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = mks_speaker_dispose;
|
||||
object_class->get_property = mks_speaker_get_property;
|
||||
object_class->set_property = mks_speaker_set_property;
|
||||
|
||||
/**
|
||||
* MksSpeaker:muted:
|
||||
*
|
||||
* The "muted" property denotes if audio received from the
|
||||
* instance is dropped and the remote sound device should
|
||||
* attempt to be set as muted.
|
||||
*/
|
||||
properties [PROP_MUTED] =
|
||||
g_param_spec_boolean ("muted", NULL, NULL,
|
||||
FALSE,
|
||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
mks_speaker_init (MksSpeaker *self)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* mks_speaker_get_muted:
|
||||
* @self: a #MksSpeaker
|
||||
*
|
||||
* Gets if the speaker is muted.
|
||||
*
|
||||
* Returns: %TRUE if the #MksSpeaker is muted.
|
||||
*/
|
||||
gboolean
|
||||
mks_speaker_get_muted (MksSpeaker *self)
|
||||
{
|
||||
g_return_val_if_fail (MKS_IS_SPEAKER (self), FALSE);
|
||||
|
||||
return self->muted;
|
||||
}
|
||||
|
||||
/**
|
||||
* mks_speaker_set_muted:
|
||||
* @self: a #MksSpeaker
|
||||
* @muted: if the speaker should be muted
|
||||
*
|
||||
* Sets the #MksSpeaker:muted property.
|
||||
*/
|
||||
void
|
||||
mks_speaker_set_muted (MksSpeaker *self,
|
||||
gboolean muted)
|
||||
{
|
||||
g_return_if_fail (MKS_IS_SPEAKER (self));
|
||||
|
||||
muted = !!muted;
|
||||
|
||||
if (self->muted != muted)
|
||||
{
|
||||
self->muted = muted;
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MUTED]);
|
||||
}
|
||||
}
|
45
lib/mks-speaker.h
Normal file
45
lib/mks-speaker.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* mks-speaker.h
|
||||
*
|
||||
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mks-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MKS_TYPE_SPEAKER (mks_speaker_get_type ())
|
||||
#define MKS_SPEAKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MKS_TYPE_SPEAKER, MksSpeaker))
|
||||
#define MKS_SPEAKER_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MKS_TYPE_SPEAKER, MksSpeaker const))
|
||||
#define MKS_SPEAKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MKS_TYPE_SPEAKER, MksSpeakerClass))
|
||||
#define MKS_IS_SPEAKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MKS_TYPE_SPEAKER))
|
||||
#define MKS_IS_SPEAKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MKS_TYPE_SPEAKER))
|
||||
#define MKS_SPEAKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MKS_TYPE_SPEAKER, MksSpeakerClass))
|
||||
|
||||
typedef struct _MksSpeakerClass MksSpeakerClass;
|
||||
|
||||
MKS_AVAILABLE_IN_ALL
|
||||
GType mks_speaker_get_type (void) G_GNUC_CONST;
|
||||
MKS_AVAILABLE_IN_ALL
|
||||
gboolean mks_speaker_get_muted (MksSpeaker *self);
|
||||
MKS_AVAILABLE_IN_ALL
|
||||
void mks_speaker_set_muted (MksSpeaker *self,
|
||||
gboolean muted);
|
||||
|
||||
G_END_DECLS
|
@ -35,5 +35,6 @@ typedef struct _MksMouse MksMouse;
|
||||
typedef struct _MksScreen MksScreen;
|
||||
typedef struct _MksSession MksSession;
|
||||
typedef struct _MksScreenAttributes MksScreenAttributes;
|
||||
typedef struct _MksSpeaker MksSpeaker;
|
||||
|
||||
G_END_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user