168 | 168 |
gint inhibit_keys_fd;
|
169 | 169 |
GSettings *desktop_session_settings;
|
170 | 170 |
GSettings *cinnamon_session_settings;
|
|
171 |
GSettings *sound_settings;
|
171 | 172 |
|
172 | 173 |
/* Multihead stuff */
|
173 | 174 |
GdkScreen *current_screen;
|
|
836 | 837 |
gboolean quiet)
|
837 | 838 |
{
|
838 | 839 |
const char *icon;
|
839 | |
vol = CLAMP (vol, 0, max_vol);
|
|
840 |
|
840 | 841 |
icon = get_icon_name_for_volume (muted, vol, is_mic);
|
|
842 |
|
841 | 843 |
show_osd (manager, icon, vol, OSD_ALL_OUTPUTS);
|
|
844 |
|
842 | 845 |
if (quiet == FALSE && sound_changed != FALSE && muted == FALSE) {
|
843 | |
GSettings *settings = g_settings_new ("org.cinnamon.desktop.sound");
|
844 | |
gboolean enabled = g_settings_get_boolean (settings, "volume-sound-enabled");
|
845 | |
char *sound = g_settings_get_string (settings, "volume-sound-file");
|
|
846 |
gboolean enabled = g_settings_get_boolean (manager->priv->sound_settings, "volume-sound-enabled");
|
|
847 |
char *sound = g_settings_get_string (manager->priv->sound_settings, "volume-sound-file");
|
846 | 848 |
if (enabled) {
|
847 | 849 |
ca_context_change_device (manager->priv->ca, gvc_mixer_stream_get_name (stream));
|
848 | 850 |
ca_context_play (manager->priv->ca, 1, CA_PROP_MEDIA_FILENAME, sound, NULL);
|
849 | 851 |
}
|
850 | 852 |
g_free(sound);
|
851 | |
g_object_unref (settings);
|
852 | 853 |
}
|
853 | 854 |
}
|
854 | 855 |
|
|
968 | 969 |
{
|
969 | 970 |
GvcMixerStream *stream;
|
970 | 971 |
gboolean old_muted, new_muted;
|
971 | |
guint old_vol, new_vol, norm_vol_step, osd_vol, osd_max_vol;
|
|
972 |
guint old_vol_pa, new_vol_pa, max_vol_pa;
|
|
973 |
gint vol_step_pa;
|
|
974 |
gdouble max_vol_setting_multiplier;
|
|
975 |
gint osd_vol, osd_max_vol;
|
972 | 976 |
gboolean sound_changed;
|
973 | |
GSettings *settings;
|
974 | 977 |
|
975 | 978 |
/* Find the stream that corresponds to the device, if any */
|
976 | 979 |
gboolean is_source_stream =
|
|
989 | 992 |
if (stream == NULL)
|
990 | 993 |
return;
|
991 | 994 |
|
992 | |
norm_vol_step = PA_VOLUME_NORM * VOLUME_STEP / 100;
|
993 | |
|
994 | |
settings = g_settings_new ("org.cinnamon.desktop.sound");
|
995 | |
osd_max_vol = PA_VOLUME_NORM * g_settings_get_int (settings, "maximum-volume") / 100;
|
996 | |
g_object_unref (settings);
|
|
995 |
osd_max_vol = g_settings_get_int (manager->priv->sound_settings, "maximum-volume");
|
|
996 |
max_vol_setting_multiplier = (gdouble) osd_max_vol / 100;
|
|
997 |
|
|
998 |
max_vol_pa = MIN ((guint) PA_VOLUME_NORM * max_vol_setting_multiplier, PA_VOLUME_MAX);
|
|
999 |
vol_step_pa = (max_vol_pa * ((double) VOLUME_STEP) / 100);
|
|
1000 |
|
|
1001 |
// Make the max volume divisible by our 5% step.
|
|
1002 |
max_vol_pa = (max_vol_pa / vol_step_pa) * vol_step_pa;
|
|
1003 |
|
|
1004 |
|
|
1005 |
// The volume snaps to PA_VALUE_NORM when adjusting - this is done outside our control here,
|
|
1006 |
// And this messes up the 5% step: Below we try to always end up with a percent divisible by
|
|
1007 |
// VOLUME_STEP. We round up or down to the next closest, but have to give it an extra bump at the PA_VOLUME_NORM
|
|
1008 |
// threshold or else it gets stuck.
|
|
1009 |
#define CROSSING_PA_NORM(val,step)(val >= PA_VOLUME_NORM && val - step < PA_VOLUME_NORM || \
|
|
1010 |
val <= PA_VOLUME_NORM && val + step > PA_VOLUME_NORM)
|
997 | 1011 |
|
998 | 1012 |
/* FIXME: this is racy */
|
999 | |
new_vol = old_vol = gvc_mixer_stream_get_volume (stream);
|
|
1013 |
new_vol_pa = old_vol_pa = gvc_mixer_stream_get_volume (stream);
|
1000 | 1014 |
new_muted = old_muted = gvc_mixer_stream_get_is_muted (stream);
|
1001 | 1015 |
sound_changed = FALSE;
|
1002 | 1016 |
|
|
1006 | 1020 |
new_muted = !old_muted;
|
1007 | 1021 |
break;
|
1008 | 1022 |
case C_DESKTOP_MEDIA_KEY_VOLUME_DOWN:
|
1009 | |
if (old_vol <= norm_vol_step) {
|
1010 | |
new_vol = 0;
|
|
1023 |
if (old_vol_pa <= vol_step_pa) {
|
|
1024 |
new_vol_pa = 0;
|
1011 | 1025 |
new_muted = TRUE;
|
1012 | 1026 |
} else {
|
1013 | |
new_vol = old_vol - norm_vol_step;
|
|
1027 |
if (old_vol_pa % vol_step_pa > 0 && !CROSSING_PA_NORM (old_vol_pa, vol_step_pa)) {
|
|
1028 |
new_vol_pa = (old_vol_pa / vol_step_pa * vol_step_pa);
|
|
1029 |
} else {
|
|
1030 |
|
|
1031 |
new_vol_pa = (old_vol_pa / vol_step_pa * vol_step_pa) - vol_step_pa;
|
|
1032 |
}
|
1014 | 1033 |
}
|
1015 | 1034 |
break;
|
1016 | 1035 |
case C_DESKTOP_MEDIA_KEY_VOLUME_UP:
|
1017 | 1036 |
new_muted = FALSE;
|
1018 | 1037 |
/* When coming out of mute only increase the volume if it was 0 */
|
1019 | |
if (!old_muted || old_vol == 0)
|
1020 | |
new_vol = MIN (old_vol + norm_vol_step, osd_max_vol);
|
|
1038 |
if (!old_muted || old_vol_pa == 0)
|
|
1039 |
if (old_vol_pa % vol_step_pa > 0 && !CROSSING_PA_NORM (old_vol_pa, vol_step_pa)) {
|
|
1040 |
new_vol_pa = MIN (old_vol_pa / vol_step_pa * vol_step_pa, max_vol_pa);
|
|
1041 |
} else {
|
|
1042 |
new_vol_pa = MIN (old_vol_pa / vol_step_pa * vol_step_pa + vol_step_pa, max_vol_pa);
|
|
1043 |
}
|
1021 | 1044 |
break;
|
1022 | 1045 |
}
|
1023 | 1046 |
|
|
1026 | 1049 |
sound_changed = TRUE;
|
1027 | 1050 |
}
|
1028 | 1051 |
|
1029 | |
if (old_vol != new_vol) {
|
1030 | |
if (gvc_mixer_stream_set_volume (stream, new_vol) != FALSE) {
|
|
1052 |
if (old_vol_pa != new_vol_pa) {
|
|
1053 |
if (gvc_mixer_stream_set_volume (stream, new_vol_pa) != FALSE) {
|
1031 | 1054 |
gvc_mixer_stream_push_volume (stream);
|
1032 | 1055 |
sound_changed = TRUE;
|
1033 | 1056 |
}
|
1034 | 1057 |
}
|
1035 | 1058 |
|
1036 | |
if (type == C_DESKTOP_MEDIA_KEY_VOLUME_DOWN && old_vol == 0 && old_muted)
|
1037 | |
osd_vol = -1;
|
1038 | |
else if (type == C_DESKTOP_MEDIA_KEY_VOLUME_UP && old_vol == osd_max_vol && !old_muted)
|
1039 | |
osd_vol = 101;
|
|
1059 |
if (type == C_DESKTOP_MEDIA_KEY_VOLUME_DOWN && old_vol_pa == 0 && old_muted)
|
|
1060 |
// This should bottom out at 0. At -1 (old value), the OSD doesn't show a bar.
|
|
1061 |
osd_vol = 0;
|
|
1062 |
else if (type == C_DESKTOP_MEDIA_KEY_VOLUME_UP && (old_vol_pa == max_vol_pa) && !old_muted)
|
|
1063 |
osd_vol = 100;
|
1040 | 1064 |
else if (!new_muted)
|
1041 | |
osd_vol = (int) (100 * (double) new_vol / osd_max_vol);
|
|
1065 |
osd_vol = CLAMP ((int) (100 * ((double) new_vol_pa / max_vol_pa)), 0, 100);
|
1042 | 1066 |
else
|
1043 | 1067 |
osd_vol = 0;
|
1044 | 1068 |
show_sound_osd (manager, stream, is_source_stream, osd_vol, osd_max_vol, new_muted, sound_changed, quiet);
|
|
1825 | 1849 |
do_url_action (manager, "ghelp", timestamp);
|
1826 | 1850 |
break;
|
1827 | 1851 |
case C_DESKTOP_MEDIA_KEY_SCREENSHOT:
|
1828 | |
execute (manager, "gnome-screenshot", FALSE, TRUE);
|
|
1852 |
execute (manager, "gnome-screenshot", FALSE, FALSE);
|
1829 | 1853 |
break;
|
1830 | 1854 |
case C_DESKTOP_MEDIA_KEY_WINDOW_SCREENSHOT:
|
1831 | 1855 |
execute (manager, "gnome-screenshot --window", FALSE, TRUE);
|
|
1834 | 1858 |
execute (manager, "gnome-screenshot --area", FALSE, TRUE);
|
1835 | 1859 |
break;
|
1836 | 1860 |
case C_DESKTOP_MEDIA_KEY_SCREENSHOT_CLIP:
|
1837 | |
execute (manager, "gnome-screenshot --clipboard", FALSE, TRUE);
|
|
1861 |
execute (manager, "gnome-screenshot --clipboard", FALSE, FALSE);
|
1838 | 1862 |
break;
|
1839 | 1863 |
case C_DESKTOP_MEDIA_KEY_WINDOW_SCREENSHOT_CLIP:
|
1840 | 1864 |
execute (manager, "gnome-screenshot --window --clipboard", FALSE, TRUE);
|
|
1965 | 1989 |
manager->priv->power_settings = g_settings_new (SETTINGS_POWER_DIR);
|
1966 | 1990 |
manager->priv->media_key_settings = g_settings_new ("org.cinnamon.settings-daemon.plugins.media-keys");
|
1967 | 1991 |
|
|
1992 |
manager->priv->sound_settings = g_settings_new ("org.cinnamon.desktop.sound");
|
|
1993 |
|
1968 | 1994 |
/* Logic from http://git.gnome.org/browse/gnome-shell/tree/js/ui/status/accessibility.js#n163 */
|
1969 | 1995 |
manager->priv->interface_settings = g_settings_new (SETTINGS_INTERFACE_DIR);
|
1970 | 1996 |
g_signal_connect (G_OBJECT (manager->priv->interface_settings), "changed::gtk-theme",
|
|
2101 | 2127 |
priv->media_key_settings = NULL;
|
2102 | 2128 |
}
|
2103 | 2129 |
|
|
2130 |
g_clear_object (&priv->sound_settings);
|
|
2131 |
|
2104 | 2132 |
if (priv->power_screen_proxy) {
|
2105 | 2133 |
g_object_unref (priv->power_screen_proxy);
|
2106 | 2134 |
priv->power_screen_proxy = NULL;
|