using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace RemSound.App;
///
/// Shows a dialog FRONT-AND-CENTRE with keyboard focus, WITHOUT disturbing the main window — it can
/// stay minimised in the tray the whole time. We give the dialog a momentary, top-most, off-taskbar
/// 1×1 owner window at screen centre and force THAT owner to the foreground (the AttachThreadInput
/// dance bypasses Windows' focus-stealing lock), so the modal dialog opens on top with focus and a
/// screen reader lands on it wherever RemSound happens to be sitting. Used for every warning/notice
/// the app raises (mic-privacy, Realtek, About-after-update, config-moved), so a minimised RemSound
/// never leaves a blind user with a dialog dinging away behind everything.
///
internal static class ForegroundDialog
{
/// Run with a foreground 1×1 owner; returns its result.
public static T Show(Func show)
{
var area = Screen.PrimaryScreen?.WorkingArea ?? new Rectangle(0, 0, 800, 600);
using var owner = new Form
{
ShowInTaskbar = false,
FormBorderStyle = FormBorderStyle.None,
StartPosition = FormStartPosition.Manual,
Size = new Size(1, 1),
Location = new Point(area.X + area.Width / 2, area.Y + area.Height / 2),
TopMost = true,
};
owner.Show();
ForceForeground(owner.Handle);
try { return show(owner); }
finally { try { owner.Close(); } catch { /* ignore */ } }
}
/// Void convenience overload.
public static void Show(Action show) =>
Show