private void RefreshDevices(bool UpdateListView) { listDevices.Clear(); EndPoints.RefreshDevices(RenderType, UpdateListView); if (EndPoints.DeviceNames.Count == 0) { return; } CurrentDevice = EndPoints.GetDefaultDevice(RenderType); if (!UpdateListView) { return; } listDevices.ItemSelectionChanged -= listDevices_ItemSelectionChanged; listDevices.BeginUpdate(); for (var i = 0; i < EndPoints.DeviceNames.Count; i++) { var item = new ListViewItem { ImageIndex = i, Text = EndPoints.DeviceNames[i], Selected = i == CurrentDevice }; listDevices.Items.Add(item); } listDevices.LargeImageList.Images[CurrentDevice].Dispose(); listDevices.LargeImageList.Images[CurrentDevice] = DeviceIcons.DefaultIcons.Images[CurrentDevice]; listDevices.EndUpdate(); listDevices.ItemSelectionChanged += listDevices_ItemSelectionChanged; }
private void notifyIcon1_MouseUp(object sender, MouseEventArgs e) { if (ModifierKeys.HasFlag(Keys.Alt)) { return; } switch (e.Button) { case MouseButtons.Left: if (!Program.stfu) { timer1.Enabled = true; Show(); Activate(); } break; case MouseButtons.Right: if (EndPoints.DeviceNames.Count > 0) { CurrentDevice = CurrentDevice == EndPoints.DeviceNames.Count - 1 ? 0 : CurrentDevice + 1; EndPoints.SetDefaultDevice(CurrentDevice); if (!Program.stfu) { notifyIcon.ShowBalloonTip(0, "Audio device changed", EndPoints.DeviceNames[CurrentDevice], ToolTipIcon.Info); } } break; } VolBar.RegisterDevice(RenderType); }
private void HotKeyPressed() { if (Visible) { return; // Let's not make it complicated here... } VolBar.UnregisterDevice(); RenderType = EDataFlow.eRender; RefreshDevices(false); if (EndPoints.DeviceNames.Count == 0) { return; } CurrentDevice = CurrentDevice == EndPoints.DeviceNames.Count - 1 ? 0 : CurrentDevice + 1; EndPoints.SetDefaultDevice(CurrentDevice); if (!Program.stfu) { notifyIcon.ShowBalloonTip(0, "Audio device changed", EndPoints.DeviceNames[CurrentDevice], ToolTipIcon.Info); } }
private void listDevices_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { listDevices.BeginUpdate(); if (!e.IsSelected) { listDevices.LargeImageList.Images[CurrentDevice].Dispose(); listDevices.LargeImageList.Images[CurrentDevice] = DeviceIcons.NormalIcons.Images[CurrentDevice]; } else if (CurrentDevice != e.ItemIndex) { CurrentDevice = e.ItemIndex; EndPoints.SetDefaultDevice(CurrentDevice); VolBar.UnregisterDevice(); VolBar.RegisterDevice(RenderType); listDevices.LargeImageList.Images[CurrentDevice].Dispose(); listDevices.LargeImageList.Images[CurrentDevice] = DeviceIcons.DefaultIcons.Images[CurrentDevice]; } listDevices.EndUpdate(); }
private static void Main(string[] args) { if (args.Length > 0) { var cmdArgsJoined = string.Join(" ", args); var cmdArgs = cmdArgsJoined.Split('-'); foreach (var arg in cmdArgs) { if (string.IsNullOrWhiteSpace(arg)) { continue; } var purecmd = arg.Length > 1 ? arg.Substring(1, arg.Length - 1).Trim() : ""; switch (arg.Substring(0, 1)) { case "s": stfu = true; break; case "m": Keys modifiers; var mresult = Enum.TryParse(purecmd, true, out modifiers); if (mresult) { Hotkey.hotModifiers = modifiers; } break; case "k": Keys key; var kresult = Enum.TryParse(purecmd, true, out key); if (kresult) { Hotkey.hotKey = key; } break; case "i": var devID = int.Parse(purecmd); EndPoints.RefreshDevices(EDataFlow.eRender, false); if (devID <= EndPoints.DeviceNames.Count - 1) { EndPoints.SetDefaultDevice(devID); } break; case "l": if (!AttachConsole(-1)) { AllocConsole(); } Console.WriteLine(); Console.WriteLine("Devices available:"); EndPoints.RefreshDevices(EDataFlow.eRender, false); for (var i = 0; i < EndPoints.DeviceNames.Count; i++) { Console.WriteLine(" * " + i + ": " + EndPoints.DeviceNames[i]); } FreeConsole(); SendKeys.SendWait("{ENTER}"); break; case "x": return; } } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var formSwitcher = new FormSwitcher(); Application.Run(); }