Hide Video Conferencing when muted (#19175)

This commit is contained in:
akabhirav 2022-10-19 14:48:58 +05:30 committed by GitHub
parent 16c28c788d
commit 1cfce6182d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 134 additions and 32 deletions

View File

@ -154,18 +154,27 @@ LRESULT Toolbar::WindowProcessMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARA
static bool previousShow = false;
bool show = false;
if (toolbar->cameraInUse)
if (toolbar->ToolbarHide == L"Never")
{
show = toolbar->HideToolbarWhenUnmuted ? toolbar->microphoneMuted || toolbar->cameraMuted : true;
show = true;
}
else if (toolbar->previouscameraInUse)
else if (toolbar->ToolbarHide == L"When both camera and microphone are muted")
{
VideoConferenceModule::unmuteAll();
if(!toolbar->previouscameraInUse && toolbar->cameraInUse && !toolbar->moduleSettingsUpdateScheduled)
{
VideoConferenceModule::muteAll();
}
show = !(toolbar->microphoneMuted && (toolbar->cameraMuted || !toolbar->cameraInUse));
}
else
else if (toolbar->ToolbarHide == L"When both camera and microphone are unmuted")
{
show = toolbar->microphoneMuted;
if(!toolbar->previouscameraInUse && toolbar->cameraInUse && !toolbar->moduleSettingsUpdateScheduled)
{
VideoConferenceModule::unmuteAll();
}
show = toolbar->microphoneMuted || toolbar->cameraMuted;
}
show = show || !showOverlayTimeout;
if (show)
{
@ -332,9 +341,9 @@ void Toolbar::setMicrophoneMute(bool mute)
microphoneMuted = mute;
}
void Toolbar::setHideToolbarWhenUnmuted(bool hide)
void Toolbar::setToolbarHide(std::wstring hide)
{
HideToolbarWhenUnmuted = hide;
ToolbarHide = hide;
}
void Toolbar::setTheme(std::wstring theme)

View File

@ -35,7 +35,7 @@ public:
void setMicrophoneMute(bool mute);
void setTheme(std::wstring theme);
void setHideToolbarWhenUnmuted(bool hide);
void setToolbarHide(std::wstring hide);
private:
static LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
@ -54,7 +54,7 @@ private:
std::wstring theme = L"system";
bool HideToolbarWhenUnmuted = true;
std::wstring ToolbarHide = L"Never";
uint64_t lastTimeCamOrMicMuteStateChanged{};

View File

@ -250,9 +250,9 @@ void VideoConferenceModule::onModuleSettingsChanged()
settings.imageOverlayPath = val.value();
sendOverlayImageUpdate();
}
if (const auto val = values.get_bool_value(L"hide_toolbar_when_unmuted"))
if (const auto val = values.get_string_value(L"toolbar_hide"))
{
toolbar.setHideToolbarWhenUnmuted(val.value());
toolbar.setToolbarHide(val.value());
}
const auto selectedMic = values.get_string_value(L"selected_mic");
@ -397,9 +397,9 @@ void VideoConferenceModule::init_settings()
{
settings.imageOverlayPath = val.value();
}
if (const auto val = powerToysSettings.get_bool_value(L"hide_toolbar_when_unmuted"))
if (const auto val = powerToysSettings.get_string_value(L"toolbar_hide"))
{
toolbar.setHideToolbarWhenUnmuted(val.value());
toolbar.setToolbarHide(val.value());
}
if (const auto val = powerToysSettings.get_string_value(L"selected_mic"); val && *val != settings.selectedMicrophone)
{
@ -549,6 +549,19 @@ void VideoConferenceModule::unmuteAll()
}
}
void VideoConferenceModule::muteAll()
{
if (!getVirtualCameraMuteState())
{
reverseVirtualCameraMuteState();
}
if (!getMicrophoneMuteState())
{
reverseMicrophoneMute();
}
}
void VideoConferenceModule::disable()
{
if (_enabled)

View File

@ -53,6 +53,7 @@ public:
void sendOverlayImageUpdate();
static void unmuteAll();
static void muteAll();
static void reverseMicrophoneMute();
static bool getMicrophoneMuteState();
static void reverseVirtualCameraMuteState();

View File

@ -43,8 +43,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library
Key = "O",
Code = 79,
});
this.HideToolbarWhenUnmuted = new BoolProperty(true);
}
[JsonPropertyName("mute_camera_and_microphone_hotkey")]
@ -74,8 +72,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("theme")]
public StringProperty Theme { get; set; }
[JsonPropertyName("hide_toolbar_when_unmuted")]
public BoolProperty HideToolbarWhenUnmuted { get; set; }
[JsonPropertyName("toolbar_hide")]
public StringProperty ToolbarHide { get; set; } = "Never";
// converts the current to a json string.
public string ToJsonString()

View File

@ -12,6 +12,7 @@ using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
@ -98,8 +99,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
SelectOverlayImage = new ButtonClickCommand(SelectOverlayImageAction);
ClearOverlayImage = new ButtonClickCommand(ClearOverlayImageAction);
_hideToolbarWhenUnmuted = Settings.Properties.HideToolbarWhenUnmuted.Value;
switch (Settings.Properties.ToolbarPosition.Value)
{
case "Top left corner":
@ -133,6 +132,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
break;
}
switch (Settings.Properties.ToolbarHide.Value)
{
case "Never":
_toolbarHideIndex = 0;
break;
case "When both camera and microphone are unmuted":
_toolbarHideIndex = 1;
break;
case "When both camera and microphone are muted":
_toolbarHideIndex = 2;
break;
}
if (shouldSaveSettings)
{
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
@ -142,12 +154,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _isEnabled;
private int _toolbarPositionIndex;
private int _toolbarMonitorIndex;
private int _toolbarHideIndex;
private HotkeySettings _cameraAndMicrophoneMuteHotkey;
private HotkeySettings _microphoneMuteHotkey;
private HotkeySettings _cameraMuteHotkey;
private int _selectedCameraIndex = -1;
private int _selectedMicrophoneIndex;
private bool _hideToolbarWhenUnmuted;
public List<string> CameraNames { get; }
@ -380,20 +392,32 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool HideToolbarWhenUnmuted
public int ToolbarHideIndex
{
get
{
return _hideToolbarWhenUnmuted;
return _toolbarHideIndex;
}
set
{
if (value != _hideToolbarWhenUnmuted)
if (value != _toolbarHideIndex)
{
_hideToolbarWhenUnmuted = value;
Settings.Properties.HideToolbarWhenUnmuted.Value = value;
RaisePropertyChanged(nameof(HideToolbarWhenUnmuted));
_toolbarHideIndex = value;
switch (_toolbarHideIndex)
{
case 0:
Settings.Properties.ToolbarHide.Value = "Never";
break;
case 1:
Settings.Properties.ToolbarHide.Value = "When both camera and microphone are unmuted";
break;
case 2:
Settings.Properties.ToolbarHide.Value = "When both camera and microphone are muted";
break;
}
RaisePropertyChanged(nameof(ToolbarHideIndex));
}
}
}

View File

@ -1 +1,42 @@
{"version":"1.0","name":"Video Conference","properties":{"mute_camera_and_microphone_hotkey":{"value":{"win":false,"ctrl":false,"alt":false,"shift":true,"code":73,"key":""}},"mute_microphone_hotkey":{"value":{"win":false,"ctrl":false,"alt":false,"shift":true,"code":68,"key":""}},"mute_camera_hotkey":{"value":{"win":false,"ctrl":false,"alt":false,"shift":true,"code":86,"key":""}},"selected_camera":{"value":"USB Video Device"},"toolbar_position":{"value":"Bottom center"},"toolbar_monitor":{"value":"All monitors"},"camera_overlay_image_path":{"value":""},"theme":{"value":"light"},"hide_toolbar_when_unmuted":{"value":false}}}
{
"version": "1.0",
"name": "Video Conference",
"properties": {
"camera_overlay_image_path": { "value": "" },
"toolbar_hide": { "value": "Never" },
"mute_camera_and_microphone_hotkey": {
"value": {
"win": false,
"ctrl": false,
"alt": false,
"shift": true,
"code": 73,
"key": ""
}
},
"mute_camera_hotkey": {
"value": {
"win": false,
"ctrl": false,
"alt": false,
"shift": true,
"code": 86,
"key": ""
}
},
"mute_microphone_hotkey": {
"value": {
"win": false,
"ctrl": false,
"alt": false,
"shift": true,
"code": 68,
"key": ""
}
},
"selected_camera": { "value": "USB Video Device" },
"theme": { "value": "light" },
"toolbar_monitor": { "value": "All monitors" },
"toolbar_position": { "value": "Bottom center" }
}
}

View File

@ -255,8 +255,17 @@
<data name="VideoConference_ToolbarMonitor_All.Content" xml:space="preserve">
<value>All monitors</value>
</data>
<data name="VideoConference_HideToolbarWhenUnmuted.Content" xml:space="preserve">
<value>Hide toolbar when both camera and microphone are unmuted</value>
<data name="VideoConference_ToolbarHide.Header" xml:space="preserve">
<value>Hide toolbar</value>
</data>
<data name="VideoConference_ToolbarHideMuted.Content" xml:space="preserve">
<value>When both camera and microphone are muted</value>
</data>
<data name="VideoConference_ToolbarHideNever.Content" xml:space="preserve">
<value>Never</value>
</data>
<data name="VideoConference_ToolbarHideUnmuted.Content" xml:space="preserve">
<value>When both camera and microphone are unmuted</value>
</data>
<data name="VideoConference.ModuleTitle" xml:space="preserve">
<value>Video Conference Mute</value>

View File

@ -145,8 +145,15 @@
</controls:Setting.ActionContent>
</controls:Setting>
<Rectangle Style="{StaticResource ExpanderSeparatorStyle}" />
<CheckBox x:Uid="VideoConference_HideToolbarWhenUnmuted" IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.HideToolbarWhenUnmuted}" Margin="{StaticResource ExpanderSettingMargin}" />
<controls:Setting x:Uid="VideoConference_ToolbarHide" Style="{StaticResource ExpanderContentSettingStyle}">
<controls:Setting.ActionContent>
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{ Binding Mode=TwoWay, Path=ToolbarHideIndex}">
<ComboBoxItem x:Uid="VideoConference_ToolbarHideNever"/>
<ComboBoxItem x:Uid="VideoConference_ToolbarHideUnmuted"/>
<ComboBoxItem x:Uid="VideoConference_ToolbarHideMuted"/>
</ComboBox>
</controls:Setting.ActionContent>
</controls:Setting>
</StackPanel>
</controls:SettingExpander.Content>
</controls:SettingExpander>