wbolster / nothing-to-say

gnome shell extension to only unmute the microphone when you have something to say
GNU General Public License v2.0
247 stars 22 forks source link

Microphone level percentage not shown in the top bar #28

Open krashish8 opened 3 years ago

krashish8 commented 3 years ago

Thank you for this great extension! @wbolster

I could not find the percentage level of the microphone in the top bar, beside the microphone icon. Only the microphone icon is visible in the top bar. I am experiencing this in GNOME Shell 3.36.4 on Ubuntu 20.04.

Screenshot: image

NB: The 50% which you see on the right is the speaker's sound percentage, made available using the sound-percentage gnome-shell extension.

krashish8 commented 3 years ago

Nevermind, I understood that this is how the extension is supposed to behave. I somehow figured out how to do it myself.

A label needs to be created and inserted in the appropriate position, something like this:

const Clutter = imports.gi.Clutter;

function enable() {
  // ...
  let panel_button_label = new St.Label({
    y_expand: true,
    y_align: Clutter.ActorAlign.CENTER
  });
  panel_button_label.text = microphone.level + '%';
  Main.panel._rightBox.insert_child_at_index(panel_button_label, 0);
}

function disable() {
  // ...
  panel_button_label.destroy();
  panel_button_label = null;
}

Maybe this can be added as an option in dconf, if it is not of any general interest. I have some global shortcuts to adjust the microphone volume to some particular percentages, therefore this feature particularly interests me.

However, I cannot figure out how to update this microphone.level value each time the microphone level is updated by the global shortcut. Also, as of now, it displays 0% always.

Do you know a fix for this, or how to do this? @wbolster Any link to understand this might be helpful. I guess I need to connect this to a signal, however, I don't know how to. I am new to gnome extensions. :)

krashish8 commented 3 years ago

Well, I somehow got it working locally by connecting to the notify signal of Gvc.MixerControl for the volume property:

refresh: function() {
  // ...
  this.stream.connect('notify::volume', (stream) => {
    this.notify_volume_change();
  });
  this.notify_volume_change();
  // ...
}

notify_volume_change: function() {
  this.emit('notify::volume_change');
},

// ...

def enable() {
  // ...
  microphone.connect(
    'notify::volume_change',
    function () {
      if (microphone.muted) {
        panel_button_label.text = '0%';
      } else {
        panel_button_label.text = microphone.level + '%';
      }
    });
  // ...
}

Thank you for this extension! :smile: