Skip to content

Commit

Permalink
csd-media-keys: Show device description on volume OSD (#399)
Browse files Browse the repository at this point in the history
This allows us to pass a label to the Cinnamon OSD when a device like
headphones are plugged in. Since these outputs each have there own volume
level, this makes it easier for a user to identify what they are changing.
  • Loading branch information
JosephMcc authored Nov 19, 2024
1 parent 57b8a0a commit 1dbe86a
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions plugins/media-keys/csd-media-keys-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ cinnamon_proxy_complete (GObject *source,
static void
show_osd (CsdMediaKeysManager *manager,
const char *icon,
const char *label,
int level,
int outx,
int outy)
Expand All @@ -416,6 +417,9 @@ show_osd (CsdMediaKeysManager *manager,
if (icon)
g_variant_builder_add (&builder, "{sv}",
"icon", g_variant_new_string (icon));
if (label)
g_variant_builder_add (&builder, "{sv}",
"label", g_variant_new_string (label));
if (level >= 0)
g_variant_builder_add (&builder, "{sv}",
"level", g_variant_new_int32 (level));
Expand Down Expand Up @@ -642,7 +646,7 @@ do_eject_action (CsdMediaKeysManager *manager)
}

/* Show the dialogue */
show_osd (manager, "media-eject-symbolic", -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
show_osd (manager, "media-eject-symbolic", NULL, -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);

/* Clean up the drive selection and exit if no suitable
* drives are found */
Expand Down Expand Up @@ -696,7 +700,7 @@ do_touchpad_osd_action (CsdMediaKeysManager *manager, gboolean state)
{
show_osd (manager,
state ? "input-touchpad-symbolic" : "touchpad-disabled-symbolic",
-1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
NULL, -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
}

static void
Expand Down Expand Up @@ -732,11 +736,23 @@ show_sound_osd (CsdMediaKeysManager *manager,
gboolean sound_changed,
gboolean quiet)
{
GvcMixerUIDevice *device;
const GvcMixerStreamPort *port;
const char *icon;

icon = get_icon_name_for_volume (muted, vol, is_mic);

show_osd (manager, icon, vol, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
port = gvc_mixer_stream_get_port (stream);
if (g_strcmp0 (gvc_mixer_stream_get_form_factor (stream), "internal") != 0 ||
(port != NULL &&
g_strcmp0 (port->port, "analog-output-speaker") != 0 &&
g_strcmp0 (port->port, "analog-output") != 0)) {
device = gvc_mixer_control_lookup_device_from_stream (manager->priv->volume, stream);
show_osd (manager, icon,
gvc_mixer_ui_device_get_description (device),
vol, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
} else {
show_osd (manager, icon, NULL, vol, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
}

if (quiet == FALSE && sound_changed != FALSE && muted == FALSE) {
gboolean enabled = g_settings_get_boolean (manager->priv->sound_settings, "volume-sound-enabled");
Expand Down Expand Up @@ -1233,7 +1249,7 @@ csd_media_player_key_pressed (CsdMediaKeysManager *manager,
if (!have_listeners) {
if (!mpris_controller_key (manager->priv->mpris_controller, key)) {
/* Popup a dialog with an (/) icon */
show_osd (manager, "action-unavailable-symbolic", -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
show_osd (manager, "action-unavailable-symbolic", NULL, -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
}
return TRUE;
}
Expand Down Expand Up @@ -1327,7 +1343,7 @@ do_video_rotate_lock_action (CsdMediaKeysManager *manager,
g_object_unref (settings);

show_osd (manager, locked ? "rotation-locked-symbolic"
: "rotation-allowed-symbolic", -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
: "rotation-allowed-symbolic", NULL, -1, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
}

static void
Expand Down Expand Up @@ -1488,7 +1504,7 @@ update_screen_cb (GObject *source_object,

/* update the dialog with the new value */
g_variant_get (variant, "(uii)", &percentage, &outx, &outy);
show_osd (manager, "display-brightness-symbolic", percentage, outx, outy);
show_osd (manager, "display-brightness-symbolic", NULL, percentage, outx, outy);
g_variant_unref (variant);
}

Expand Down Expand Up @@ -1570,7 +1586,7 @@ update_keyboard_cb (GObject *source_object,

/* update the dialog with the new value */
g_variant_get (new_percentage, "(u)", &percentage);
show_osd (manager, "keyboard-brightness-symbolic", percentage, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
show_osd (manager, "keyboard-brightness-symbolic", NULL, percentage, OSD_ALL_OUTPUTS_X, OSD_ALL_OUTPUTS_Y);
g_variant_unref (new_percentage);
}

Expand Down

0 comments on commit 1dbe86a

Please sign in to comment.