diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index a0d7a3b..403a92c 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -1,6 +1,6 @@  - net7.0-windows10.0.20348.0 + net8.0-windows10.0.20348.0 WinExe false publish\ @@ -18,8 +18,8 @@ Maassoft Maassoft 0 - 9.8.1.0 - 9.8.1.0 + 9.8.2.0 + 9.8.2.0 false true false @@ -59,6 +59,9 @@ Form + + UserControl + UserControl @@ -101,17 +104,17 @@ - - - + + + - - + + - + - - + + diff --git a/ColorControl/Forms/OptionsPanel.Designer.cs b/ColorControl/Forms/OptionsPanel.Designer.cs new file mode 100644 index 0000000..dce77fb --- /dev/null +++ b/ColorControl/Forms/OptionsPanel.Designer.cs @@ -0,0 +1,494 @@ +using System.DirectoryServices.ActiveDirectory; +using System.Drawing; +using System; + +namespace ColorControl.Forms +{ + partial class OptionsPanel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + grpOptionsModules = new System.Windows.Forms.GroupBox(); + label1 = new System.Windows.Forms.Label(); + chkModules = new System.Windows.Forms.CheckedListBox(); + grpMiscellaneousOptions = new System.Windows.Forms.GroupBox(); + btnOptionsColorProfiles = new System.Windows.Forms.Button(); + btnSetShortcutScreenSaver = new System.Windows.Forms.Button(); + label11 = new System.Windows.Forms.Label(); + edtBlankScreenSaverShortcut = new System.Windows.Forms.TextBox(); + lblFixChromeFontsDescription = new System.Windows.Forms.Label(); + chkFixChromeFonts = new System.Windows.Forms.CheckBox(); + grpGeneralOptions = new System.Windows.Forms.GroupBox(); + btnOptionsLog = new System.Windows.Forms.Button(); + btnOptionsAdvanced = new System.Windows.Forms.Button(); + chkOptionsUseDarkMode = new System.Windows.Forms.CheckBox(); + chkAutoInstallUpdates = new System.Windows.Forms.CheckBox(); + btnStartStopService = new System.Windows.Forms.Button(); + btnElevationInfo = new System.Windows.Forms.Button(); + rbElevationService = new System.Windows.Forms.RadioButton(); + rbElevationProcess = new System.Windows.Forms.RadioButton(); + rbElevationAdmin = new System.Windows.Forms.RadioButton(); + label8 = new System.Windows.Forms.Label(); + rbElevationNone = new System.Windows.Forms.RadioButton(); + chkGdiScaling = new System.Windows.Forms.CheckBox(); + chkCheckForUpdates = new System.Windows.Forms.CheckBox(); + chkMinimizeToSystemTray = new System.Windows.Forms.CheckBox(); + chkMinimizeOnClose = new System.Windows.Forms.CheckBox(); + chkStartMinimized = new System.Windows.Forms.CheckBox(); + chkStartAfterLogin = new System.Windows.Forms.CheckBox(); + mnuColorProfiles = new System.Windows.Forms.ContextMenuStrip(components); + miCreateHDRColorProfile = new System.Windows.Forms.ToolStripMenuItem(); + miCreateSDRColorProfile = new System.Windows.Forms.ToolStripMenuItem(); + grpOptionsModules.SuspendLayout(); + grpMiscellaneousOptions.SuspendLayout(); + grpGeneralOptions.SuspendLayout(); + mnuColorProfiles.SuspendLayout(); + SuspendLayout(); + // + // grpOptionsModules + // + grpOptionsModules.Controls.Add(label1); + grpOptionsModules.Controls.Add(chkModules); + grpOptionsModules.Location = new Point(11, 223); + grpOptionsModules.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpOptionsModules.Name = "grpOptionsModules"; + grpOptionsModules.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpOptionsModules.Size = new Size(658, 131); + grpOptionsModules.TabIndex = 11; + grpOptionsModules.TabStop = false; + grpOptionsModules.Text = "Modules"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(7, 19); + label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label1.Name = "label1"; + label1.Size = new Size(511, 15); + label1.TabIndex = 7; + label1.Text = "Here you can disable modules you do not want. A restart is required for a change to have effect."; + // + // chkModules + // + chkModules.ColumnWidth = 200; + chkModules.FormattingEnabled = true; + chkModules.Location = new Point(7, 40); + chkModules.MultiColumn = true; + chkModules.Name = "chkModules"; + chkModules.Size = new Size(507, 76); + chkModules.TabIndex = 0; + chkModules.ItemCheck += chkModules_ItemCheck; + // + // grpMiscellaneousOptions + // + grpMiscellaneousOptions.Controls.Add(btnOptionsColorProfiles); + grpMiscellaneousOptions.Controls.Add(btnSetShortcutScreenSaver); + grpMiscellaneousOptions.Controls.Add(label11); + grpMiscellaneousOptions.Controls.Add(edtBlankScreenSaverShortcut); + grpMiscellaneousOptions.Controls.Add(lblFixChromeFontsDescription); + grpMiscellaneousOptions.Controls.Add(chkFixChromeFonts); + grpMiscellaneousOptions.Location = new Point(11, 360); + grpMiscellaneousOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpMiscellaneousOptions.Name = "grpMiscellaneousOptions"; + grpMiscellaneousOptions.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpMiscellaneousOptions.Size = new Size(658, 131); + grpMiscellaneousOptions.TabIndex = 5; + grpMiscellaneousOptions.TabStop = false; + grpMiscellaneousOptions.Text = "Miscellaneous"; + // + // btnOptionsColorProfiles + // + btnOptionsColorProfiles.Location = new Point(538, 17); + btnOptionsColorProfiles.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnOptionsColorProfiles.Name = "btnOptionsColorProfiles"; + btnOptionsColorProfiles.Size = new Size(112, 27); + btnOptionsColorProfiles.TabIndex = 12; + btnOptionsColorProfiles.Text = "Color Profiles..."; + btnOptionsColorProfiles.UseVisualStyleBackColor = true; + btnOptionsColorProfiles.Click += btnOptionsColorProfiles_Click; + // + // btnSetShortcutScreenSaver + // + btnSetShortcutScreenSaver.Location = new Point(181, 98); + btnSetShortcutScreenSaver.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnSetShortcutScreenSaver.Name = "btnSetShortcutScreenSaver"; + btnSetShortcutScreenSaver.Size = new Size(40, 27); + btnSetShortcutScreenSaver.TabIndex = 10; + btnSetShortcutScreenSaver.Text = "Set"; + btnSetShortcutScreenSaver.UseVisualStyleBackColor = true; + btnSetShortcutScreenSaver.Click += btnSetShortcutScreenSaver_Click; + // + // label11 + // + label11.AutoSize = true; + label11.Location = new Point(7, 80); + label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label11.Name = "label11"; + label11.Size = new Size(238, 15); + label11.TabIndex = 9; + label11.Text = "Set a shortcut to start the blank screensaver:"; + // + // edtBlankScreenSaverShortcut + // + edtBlankScreenSaverShortcut.Location = new Point(7, 101); + edtBlankScreenSaverShortcut.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + edtBlankScreenSaverShortcut.Name = "edtBlankScreenSaverShortcut"; + edtBlankScreenSaverShortcut.ReadOnly = true; + edtBlankScreenSaverShortcut.Size = new Size(165, 23); + edtBlankScreenSaverShortcut.TabIndex = 7; + edtBlankScreenSaverShortcut.KeyDown += edtShortcut_KeyDown; + edtBlankScreenSaverShortcut.KeyUp += edtShortcut_KeyUp; + // + // lblFixChromeFontsDescription + // + lblFixChromeFontsDescription.AutoSize = true; + lblFixChromeFontsDescription.Location = new Point(4, 45); + lblFixChromeFontsDescription.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblFixChromeFontsDescription.Name = "lblFixChromeFontsDescription"; + lblFixChromeFontsDescription.Size = new Size(427, 15); + lblFixChromeFontsDescription.TabIndex = 6; + lblFixChromeFontsDescription.Text = "This will add the parameter --disable-lcd-text to Chrome and requires elevation."; + // + // chkFixChromeFonts + // + chkFixChromeFonts.AutoSize = true; + chkFixChromeFonts.Location = new Point(7, 22); + chkFixChromeFonts.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkFixChromeFonts.Name = "chkFixChromeFonts"; + chkFixChromeFonts.Size = new Size(378, 19); + chkFixChromeFonts.TabIndex = 4; + chkFixChromeFonts.Text = "ClearType: fix bad fonts in Chrome (turn on grayscale anti-aliasing)"; + chkFixChromeFonts.UseVisualStyleBackColor = true; + chkFixChromeFonts.CheckedChanged += chkFixChromeFonts_CheckedChanged; + // + // grpGeneralOptions + // + grpGeneralOptions.Controls.Add(btnOptionsLog); + grpGeneralOptions.Controls.Add(btnOptionsAdvanced); + grpGeneralOptions.Controls.Add(chkOptionsUseDarkMode); + grpGeneralOptions.Controls.Add(chkAutoInstallUpdates); + grpGeneralOptions.Controls.Add(btnStartStopService); + grpGeneralOptions.Controls.Add(btnElevationInfo); + grpGeneralOptions.Controls.Add(rbElevationService); + grpGeneralOptions.Controls.Add(rbElevationProcess); + grpGeneralOptions.Controls.Add(rbElevationAdmin); + grpGeneralOptions.Controls.Add(label8); + grpGeneralOptions.Controls.Add(rbElevationNone); + grpGeneralOptions.Controls.Add(chkGdiScaling); + grpGeneralOptions.Controls.Add(chkCheckForUpdates); + grpGeneralOptions.Controls.Add(chkMinimizeToSystemTray); + grpGeneralOptions.Controls.Add(chkMinimizeOnClose); + grpGeneralOptions.Controls.Add(chkStartMinimized); + grpGeneralOptions.Controls.Add(chkStartAfterLogin); + grpGeneralOptions.Location = new Point(7, 6); + grpGeneralOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpGeneralOptions.Name = "grpGeneralOptions"; + grpGeneralOptions.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpGeneralOptions.Size = new Size(662, 211); + grpGeneralOptions.TabIndex = 2; + grpGeneralOptions.TabStop = false; + grpGeneralOptions.Text = "General"; + // + // btnOptionsLog + // + btnOptionsLog.Location = new Point(103, 172); + btnOptionsLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnOptionsLog.Name = "btnOptionsLog"; + btnOptionsLog.Size = new Size(88, 27); + btnOptionsLog.TabIndex = 68; + btnOptionsLog.Text = "Logging..."; + btnOptionsLog.UseVisualStyleBackColor = true; + btnOptionsLog.Click += btnOptionsLog_Click; + // + // btnOptionsAdvanced + // + btnOptionsAdvanced.Location = new Point(7, 172); + btnOptionsAdvanced.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnOptionsAdvanced.Name = "btnOptionsAdvanced"; + btnOptionsAdvanced.Size = new Size(88, 27); + btnOptionsAdvanced.TabIndex = 11; + btnOptionsAdvanced.Text = "Advanced..."; + btnOptionsAdvanced.UseVisualStyleBackColor = true; + btnOptionsAdvanced.Click += btnOptionsAdvanced_Click; + // + // chkOptionsUseDarkMode + // + chkOptionsUseDarkMode.AutoSize = true; + chkOptionsUseDarkMode.Location = new Point(216, 47); + chkOptionsUseDarkMode.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkOptionsUseDarkMode.Name = "chkOptionsUseDarkMode"; + chkOptionsUseDarkMode.Size = new Size(164, 19); + chkOptionsUseDarkMode.TabIndex = 67; + chkOptionsUseDarkMode.Text = "Dark Mode (experimental)"; + chkOptionsUseDarkMode.UseVisualStyleBackColor = true; + chkOptionsUseDarkMode.CheckedChanged += chkOptionsUseDarkMode_CheckedChanged; + // + // chkAutoInstallUpdates + // + chkAutoInstallUpdates.AutoSize = true; + chkAutoInstallUpdates.Location = new Point(7, 147); + chkAutoInstallUpdates.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkAutoInstallUpdates.Name = "chkAutoInstallUpdates"; + chkAutoInstallUpdates.Size = new Size(179, 19); + chkAutoInstallUpdates.TabIndex = 66; + chkAutoInstallUpdates.Text = "Automatically install updates"; + chkAutoInstallUpdates.UseVisualStyleBackColor = true; + chkAutoInstallUpdates.CheckedChanged += chkAutoInstallUpdates_CheckedChanged; + // + // btnStartStopService + // + btnStartStopService.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; + btnStartStopService.Location = new Point(614, 129); + btnStartStopService.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnStartStopService.Name = "btnStartStopService"; + btnStartStopService.Size = new Size(40, 27); + btnStartStopService.TabIndex = 65; + btnStartStopService.Text = "Start"; + btnStartStopService.UseVisualStyleBackColor = true; + btnStartStopService.Click += btnStartStopService_Click; + // + // btnElevationInfo + // + btnElevationInfo.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; + btnElevationInfo.Location = new Point(329, 67); + btnElevationInfo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnElevationInfo.Name = "btnElevationInfo"; + btnElevationInfo.Size = new Size(22, 27); + btnElevationInfo.TabIndex = 64; + btnElevationInfo.Text = "?"; + btnElevationInfo.UseVisualStyleBackColor = true; + btnElevationInfo.Click += btnElevationInfo_Click; + // + // rbElevationService + // + rbElevationService.AutoSize = true; + rbElevationService.Location = new Point(216, 133); + rbElevationService.Name = "rbElevationService"; + rbElevationService.Size = new Size(136, 19); + rbElevationService.TabIndex = 63; + rbElevationService.TabStop = true; + rbElevationService.Tag = "2"; + rbElevationService.Text = "Use Windows Service"; + rbElevationService.UseVisualStyleBackColor = true; + rbElevationService.CheckedChanged += rbElevationNone_CheckedChanged; + // + // rbElevationProcess + // + rbElevationProcess.AutoSize = true; + rbElevationProcess.Location = new Point(216, 154); + rbElevationProcess.Name = "rbElevationProcess"; + rbElevationProcess.Size = new Size(189, 19); + rbElevationProcess.TabIndex = 62; + rbElevationProcess.TabStop = true; + rbElevationProcess.Tag = "3"; + rbElevationProcess.Text = "Use dedicated elevated process"; + rbElevationProcess.UseVisualStyleBackColor = true; + rbElevationProcess.CheckedChanged += rbElevationNone_CheckedChanged; + // + // rbElevationAdmin + // + rbElevationAdmin.AutoSize = true; + rbElevationAdmin.Location = new Point(216, 112); + rbElevationAdmin.Name = "rbElevationAdmin"; + rbElevationAdmin.Size = new Size(97, 19); + rbElevationAdmin.TabIndex = 61; + rbElevationAdmin.TabStop = true; + rbElevationAdmin.Tag = "1"; + rbElevationAdmin.Text = "Run as admin"; + rbElevationAdmin.UseVisualStyleBackColor = true; + rbElevationAdmin.CheckedChanged += rbElevationNone_CheckedChanged; + // + // label8 + // + label8.AutoSize = true; + label8.Location = new Point(216, 73); + label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label8.Name = "label8"; + label8.Size = new Size(105, 15); + label8.TabIndex = 60; + label8.Text = "Elevation-method:"; + // + // rbElevationNone + // + rbElevationNone.AutoSize = true; + rbElevationNone.Location = new Point(216, 91); + rbElevationNone.Name = "rbElevationNone"; + rbElevationNone.Size = new Size(54, 19); + rbElevationNone.TabIndex = 10; + rbElevationNone.TabStop = true; + rbElevationNone.Tag = "0"; + rbElevationNone.Text = "None"; + rbElevationNone.UseVisualStyleBackColor = true; + rbElevationNone.CheckedChanged += rbElevationNone_CheckedChanged; + // + // chkGdiScaling + // + chkGdiScaling.AutoSize = true; + chkGdiScaling.Location = new Point(216, 22); + chkGdiScaling.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkGdiScaling.Name = "chkGdiScaling"; + chkGdiScaling.Size = new Size(197, 19); + chkGdiScaling.TabIndex = 7; + chkGdiScaling.Text = "Use GDI Scaling (requires restart)"; + chkGdiScaling.UseVisualStyleBackColor = true; + chkGdiScaling.CheckedChanged += chkGdiScaling_CheckedChanged; + // + // chkCheckForUpdates + // + chkCheckForUpdates.AutoSize = true; + chkCheckForUpdates.Location = new Point(7, 122); + chkCheckForUpdates.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkCheckForUpdates.Name = "chkCheckForUpdates"; + chkCheckForUpdates.Size = new Size(197, 19); + chkCheckForUpdates.TabIndex = 6; + chkCheckForUpdates.Text = "Automatically check for updates"; + chkCheckForUpdates.UseVisualStyleBackColor = true; + chkCheckForUpdates.CheckedChanged += chkCheckForUpdates_CheckedChanged; + // + // chkMinimizeToSystemTray + // + chkMinimizeToSystemTray.AutoSize = true; + chkMinimizeToSystemTray.Location = new Point(7, 97); + chkMinimizeToSystemTray.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkMinimizeToSystemTray.Name = "chkMinimizeToSystemTray"; + chkMinimizeToSystemTray.Size = new Size(152, 19); + chkMinimizeToSystemTray.TabIndex = 5; + chkMinimizeToSystemTray.Text = "Minimize to system tray"; + chkMinimizeToSystemTray.UseVisualStyleBackColor = true; + chkMinimizeToSystemTray.CheckedChanged += chkMinimizeToSystemTray_CheckedChanged; + // + // chkMinimizeOnClose + // + chkMinimizeOnClose.AutoSize = true; + chkMinimizeOnClose.Location = new Point(7, 72); + chkMinimizeOnClose.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkMinimizeOnClose.Name = "chkMinimizeOnClose"; + chkMinimizeOnClose.Size = new Size(122, 19); + chkMinimizeOnClose.TabIndex = 4; + chkMinimizeOnClose.Text = "Minimize on close"; + chkMinimizeOnClose.UseVisualStyleBackColor = true; + chkMinimizeOnClose.CheckedChanged += chkMinimizeOnClose_CheckedChanged; + // + // chkStartMinimized + // + chkStartMinimized.AutoSize = true; + chkStartMinimized.Location = new Point(7, 47); + chkStartMinimized.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkStartMinimized.Name = "chkStartMinimized"; + chkStartMinimized.Size = new Size(109, 19); + chkStartMinimized.TabIndex = 3; + chkStartMinimized.Text = "Start minimized"; + chkStartMinimized.UseVisualStyleBackColor = true; + // + // chkStartAfterLogin + // + chkStartAfterLogin.AutoSize = true; + chkStartAfterLogin.Location = new Point(7, 22); + chkStartAfterLogin.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkStartAfterLogin.Name = "chkStartAfterLogin"; + chkStartAfterLogin.Size = new Size(183, 19); + chkStartAfterLogin.TabIndex = 2; + chkStartAfterLogin.Text = "Automatically start after login"; + chkStartAfterLogin.UseVisualStyleBackColor = true; + chkStartAfterLogin.CheckedChanged += chkStartAfterLogin_CheckedChanged; + // + // mnuColorProfiles + // + mnuColorProfiles.ImageScalingSize = new Size(20, 20); + mnuColorProfiles.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { miCreateHDRColorProfile, miCreateSDRColorProfile }); + mnuColorProfiles.Name = "mnuLgButtons"; + mnuColorProfiles.Size = new Size(214, 48); + // + // miCreateHDRColorProfile + // + miCreateHDRColorProfile.Name = "miCreateHDRColorProfile"; + miCreateHDRColorProfile.Size = new Size(213, 22); + miCreateHDRColorProfile.Text = "Create HDR Color Profile..."; + miCreateHDRColorProfile.Click += miCreateHDRColorProfile_Click; + // + // miCreateSDRColorProfile + // + miCreateSDRColorProfile.Name = "miCreateSDRColorProfile"; + miCreateSDRColorProfile.Size = new Size(213, 22); + miCreateSDRColorProfile.Text = "Create SDR Color Profile..."; + miCreateSDRColorProfile.Click += miCreateSDRColorProfile_Click; + // + // OptionsPanel + // + Controls.Add(grpOptionsModules); + Controls.Add(grpMiscellaneousOptions); + Controls.Add(grpGeneralOptions); + Name = "OptionsPanel"; + Size = new Size(732, 523); + grpOptionsModules.ResumeLayout(false); + grpOptionsModules.PerformLayout(); + grpMiscellaneousOptions.ResumeLayout(false); + grpMiscellaneousOptions.PerformLayout(); + grpGeneralOptions.ResumeLayout(false); + grpGeneralOptions.PerformLayout(); + mnuColorProfiles.ResumeLayout(false); + ResumeLayout(false); + } + + private System.Windows.Forms.GroupBox grpGeneralOptions; + private System.Windows.Forms.CheckBox chkStartMinimized; + private System.Windows.Forms.CheckBox chkStartAfterLogin; + private System.Windows.Forms.TabPage tabInfo; + private System.Windows.Forms.GroupBox grpMiscellaneousOptions; + private System.Windows.Forms.CheckBox chkFixChromeFonts; + private System.Windows.Forms.Label lblFixChromeFontsDescription; + private System.Windows.Forms.Button btnSetShortcutScreenSaver; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.TextBox edtBlankScreenSaverShortcut; + private System.Windows.Forms.CheckBox chkMinimizeOnClose; + private System.Windows.Forms.CheckBox chkMinimizeToSystemTray; + private System.Windows.Forms.CheckBox chkCheckForUpdates; + private System.Windows.Forms.CheckBox chkGdiScaling; + private System.Windows.Forms.RadioButton rbElevationService; + private System.Windows.Forms.RadioButton rbElevationProcess; + private System.Windows.Forms.RadioButton rbElevationAdmin; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.RadioButton rbElevationNone; + private System.Windows.Forms.Button btnElevationInfo; + private System.Windows.Forms.Button btnStartStopService; + private System.Windows.Forms.CheckBox chkAutoInstallUpdates; + private System.Windows.Forms.Button btnUpdate; + private System.Windows.Forms.GroupBox grpOptionsModules; + private System.Windows.Forms.CheckedListBox chkModules; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.CheckBox chkOptionsUseDarkMode; + private System.Windows.Forms.Button btnOptionsAdvanced; + private System.Windows.Forms.Button btnOptionsLog; + private System.Windows.Forms.Button btnOptionsColorProfiles; + private System.Windows.Forms.ContextMenuStrip mnuColorProfiles; + private System.Windows.Forms.ToolStripMenuItem miCreateHDRColorProfile; + private System.Windows.Forms.ToolStripMenuItem miCreateSDRColorProfile; + + #endregion + } +} diff --git a/ColorControl/Forms/OptionsPanel.cs b/ColorControl/Forms/OptionsPanel.cs new file mode 100644 index 0000000..76bb7c3 --- /dev/null +++ b/ColorControl/Forms/OptionsPanel.cs @@ -0,0 +1,363 @@ +using ColorControl.Services.Common; +using ColorControl.Shared.Common; +using ColorControl.Shared.Contracts; +using ColorControl.Shared.Forms; +using ColorControl.Shared.Services; +using ColorControl.XForms; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ColorControl.Forms; + +public partial class OptionsPanel : UserControl +{ + private readonly WinApiService _winApiService; + private readonly WinApiAdminService _winApiAdminService; + private readonly AppContextProvider _appContextProvider; + private readonly ElevationService _elevationService; + private bool _initialized; + private Config _config; + + public OptionsPanel(WinApiService winApiService, WinApiAdminService winApiAdminService, AppContextProvider appContextProvider, ElevationService elevationService) + { + _winApiService = winApiService; + _winApiAdminService = winApiAdminService; + _appContextProvider = appContextProvider; + _elevationService = elevationService; + _config = appContextProvider.GetAppContext().Config; + + InitializeComponent(); + + if (DarkModeUtils.UseDarkMode) + { + for (var i = 0; i < Controls.Count; i++) + { + var control = Controls[i]; + + DarkModeUtils.SetControlTheme(control); + } + } + + Init(); + + UpdateServiceInfo(); + } + + private void Init() + { + if (chkModules.Items.Count == 0) + { + foreach (var module in _config.Modules) + { + chkModules.Items.Add(module.DisplayName, module.IsActive); + } + } + + chkStartMinimized.Checked = _config.StartMinimized; + chkMinimizeOnClose.Checked = _config.MinimizeOnClose; + chkMinimizeToSystemTray.Checked = _config.MinimizeToTray; + chkCheckForUpdates.Checked = _config.CheckForUpdates; + chkAutoInstallUpdates.Checked = _config.AutoInstallUpdates; + chkAutoInstallUpdates.Enabled = _config.CheckForUpdates && _config.ElevationMethod == ElevationMethod.UseService; + edtBlankScreenSaverShortcut.Text = _config.ScreenSaverShortcut; + chkGdiScaling.Checked = _config.UseGdiScaling; + chkOptionsUseDarkMode.Checked = _config.UseDarkMode; + + chkStartAfterLogin.Checked = _winApiService.TaskExists(Program.TS_TASKNAME); + + chkFixChromeFonts.Enabled = _winApiService.IsChromeInstalled(); + if (chkFixChromeFonts.Enabled) + { + chkFixChromeFonts.Checked = _winApiService.IsChromeFixInstalled(); + } + + _initialized = false; + try + { + var _ = _config.ElevationMethod switch + { + ElevationMethod.None => rbElevationNone.Checked = true, + ElevationMethod.RunAsAdmin => rbElevationAdmin.Checked = true, + ElevationMethod.UseService => rbElevationService.Checked = true, + ElevationMethod.UseElevatedProcess => rbElevationProcess.Checked = true, + _ => false + }; + } + finally + { + _initialized = true; + } + } + + private void UpdateServiceInfo() + { + var text = "Use Windows Service"; + btnStartStopService.Enabled = true; + + if (_winApiService.IsServiceRunning()) + { + text += " (running)"; + btnStartStopService.Text = "Stop"; + } + else if (_winApiService.IsServiceInstalled()) + { + text += " (installed, not running)"; + btnStartStopService.Text = "Start"; + } + else + { + text += " (not installed)"; + btnStartStopService.Text = "Start"; + btnStartStopService.Enabled = false; + } + + rbElevationService.Text = text; + } + + private void edtShortcut_KeyDown(object sender, KeyEventArgs e) + { + ((TextBox)sender).Text = KeyboardShortcutManager.FormatKeyboardShortcut(e); + } + + private void edtShortcut_KeyUp(object sender, KeyEventArgs e) + { + KeyboardShortcutManager.HandleKeyboardShortcutUp(e); + } + + private void btnSetShortcutScreenSaver_Click(object sender, EventArgs e) + { + var shortcut = edtBlankScreenSaverShortcut.Text.Trim(); + + if (!KeyboardShortcutManager.ValidateShortcut(shortcut)) + { + return; + } + + _config.ScreenSaverShortcut = shortcut; + + KeyboardShortcutManager.RegisterShortcut(MainForm.SHORTCUTID_SCREENSAVER, shortcut); + } + + private void chkFixChromeFonts_CheckedChanged(object sender, EventArgs e) + { + if (_initialized) + { + _config.FixChromeFonts = chkFixChromeFonts.Checked; + + var folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + + _winApiAdminService.InstallChromeFix(chkFixChromeFonts.Checked, folder); + } + } + + private void chkAutoInstallUpdates_CheckedChanged(object sender, EventArgs e) + { + if (_initialized) + { + _config.AutoInstallUpdates = chkAutoInstallUpdates.Checked; + } + } + + private void chkMinimizeToSystemTray_CheckedChanged(object sender, EventArgs e) + { + if (_initialized) + { + _config.StartMinimized = chkStartMinimized.Checked; + Program.GetNotifyIcon().Visible = _config.MinimizeToTray; + } + } + + private void chkCheckForUpdates_CheckedChanged(object sender, EventArgs e) + { + if (_initialized) + { + _config.CheckForUpdates = chkCheckForUpdates.Checked; + chkAutoInstallUpdates.Enabled = _config.CheckForUpdates && _config.ElevationMethod == ElevationMethod.UseService; + } + } + + private void chkGdiScaling_CheckedChanged(object sender, EventArgs e) + { + _config.UseGdiScaling = chkGdiScaling.Checked; + } + + private void chkStartAfterLogin_CheckedChanged(object sender, EventArgs e) + { + if (!_initialized) + { + return; + } + var enabled = chkStartAfterLogin.Checked; + _elevationService.RegisterScheduledTask(enabled); + + rbElevationAdmin.Enabled = enabled; + if (!enabled && rbElevationAdmin.Checked) + { + rbElevationNone.Checked = true; + } + } + + private void btnElevationInfo_Click(object sender, EventArgs e) + { + MessageForms.InfoOk(Utils.ELEVATION_MSG + @$" + +NOTE: if ColorControl itself already runs as administrator this is indicated in the title: ColorControl {Application.ProductVersion} (administrator). + +Currently ColorControl is {(_winApiService.IsAdministrator() ? "" : "not ")}running as administrator. +"); + } + + private void rbElevationNone_CheckedChanged(object sender, EventArgs e) + { + if (!_initialized) + { + return; + } + + + if (sender is not RadioButton button || !button.Checked) + { + return; + } + + _elevationService.SetElevationMethod((ElevationMethod)Utils.ParseInt((string)button.Tag), chkStartAfterLogin.Checked); + + UpdateServiceInfo(); + chkAutoInstallUpdates.Enabled = _config.CheckForUpdates && _config.ElevationMethod == ElevationMethod.UseService; + } + + private async void btnStartStopService_Click(object sender, EventArgs e) + { + btnStartStopService.Enabled = false; + try + { + var start = btnStartStopService.Text == "Start"; + + if (start) + { + _winApiAdminService.StartService(); + } + else + { + _winApiAdminService.StopService(); + } + + var wait = 1500; + + while (wait > 0) + { + await Task.Delay(100); + + if (start == _winApiService.IsServiceRunning()) + { + break; + } + + wait -= 100; + } + } + finally + { + btnStartStopService.Enabled = true; + } + + UpdateServiceInfo(); + } + + private void chkMinimizeOnClose_CheckedChanged(object sender, EventArgs e) + { + _config.MinimizeOnClose = chkMinimizeOnClose.Checked; + } + + private void chkOptionsUseDarkMode_CheckedChanged(object sender, EventArgs e) + { + if (!_initialized) + { + return; + } + + _config.UseDarkMode = chkOptionsUseDarkMode.Checked; + + Program.SetTheme(_config.UseDarkMode); + } + + private void btnOptionsAdvanced_Click(object sender, EventArgs e) + { + var processPollingIntervalField = new FieldDefinition + { + FieldType = FieldType.Numeric, + Label = "Polling interval of process monitor (milliseconds).", + SubLabel = "Decreasing this delay may execute triggered presets sooner but can cause a higher CPU load", + MinValue = 50, + MaxValue = 5000, + Value = _config.ProcessMonitorPollingInterval + }; + var useRawInputField = new FieldDefinition + { + FieldType = FieldType.CheckBox, + Label = "Use Raw Input for shortcuts (hot keys)", + SubLabel = "This enables shortcuts to work during applications/games that block certain keys (like WinKey or Control). NOTE: if the application in the foreground runs with higher privileges than ColorControl, Raw Input does not work and normal hot keys are used", + Value = _config.UseRawInput + }; + var setMinTmlAndMaxTmlField = new FieldDefinition + { + FieldType = FieldType.CheckBox, + Label = "Set MinTML and MaxTML when applying color profiles", + SubLabel = "When this is enabled MinTML and MaxTML will be automatically be set to respectively the minimum luminance and the maximum luminance of the color profile", + Value = _config.SetMinTmlAndMaxTml + }; + + var values = MessageForms.ShowDialog("Advanced settings", new[] { processPollingIntervalField, useRawInputField, setMinTmlAndMaxTmlField }); + + if (values?.Any() != true) + { + return; + } + + _config.ProcessMonitorPollingInterval = processPollingIntervalField.ValueAsInt; + _config.UseRawInput = useRawInputField.ValueAsBool; + _config.SetMinTmlAndMaxTml = setMinTmlAndMaxTmlField.ValueAsBool; + + KeyboardShortcutManager.SetUseRawInput(_config.UseRawInput); + } + + private void btnOptionsLog_Click(object sender, EventArgs e) + { + LogWindow.CreateAndShow(); + } + + private void chkModules_ItemCheck(object sender, ItemCheckEventArgs e) + { + if (chkModules.Items.Count != _config.Modules.Count) + { + return; + } + var index = e.Index; + + if (index < 0) + { + return; + } + + var module = _config.Modules[index]; + module.IsActive = e.NewValue == CheckState.Checked; + } + + private void miCreateHDRColorProfile_Click(object sender, EventArgs e) + { + ColorProfileWindow.CreateAndShow(); + } + + private void btnOptionsColorProfiles_Click(object sender, EventArgs e) + { + mnuColorProfiles.ShowCustom(btnOptionsColorProfiles); + } + + private void miCreateSDRColorProfile_Click(object sender, EventArgs e) + { + ColorProfileWindow.CreateAndShow(isHDR: false); + } + +} diff --git a/ColorControl/Forms/OptionsPanel.resx b/ColorControl/Forms/OptionsPanel.resx new file mode 100644 index 0000000..ae3e096 --- /dev/null +++ b/ColorControl/Forms/OptionsPanel.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ColorControl/MainForm.Designer.cs b/ColorControl/MainForm.Designer.cs index 68fa5aa..0d0d10d 100644 --- a/ColorControl/MainForm.Designer.cs +++ b/ColorControl/MainForm.Designer.cs @@ -31,46 +31,11 @@ components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); tcMain = new System.Windows.Forms.TabControl(); - tabOptions = new System.Windows.Forms.TabPage(); - grpOptionsModules = new System.Windows.Forms.GroupBox(); - label1 = new System.Windows.Forms.Label(); - chkModules = new System.Windows.Forms.CheckedListBox(); - grpMiscellaneousOptions = new System.Windows.Forms.GroupBox(); - btnOptionsColorProfiles = new System.Windows.Forms.Button(); - btnSetShortcutScreenSaver = new System.Windows.Forms.Button(); - label11 = new System.Windows.Forms.Label(); - edtBlankScreenSaverShortcut = new System.Windows.Forms.TextBox(); - lblFixChromeFontsDescription = new System.Windows.Forms.Label(); - chkFixChromeFonts = new System.Windows.Forms.CheckBox(); - grpGeneralOptions = new System.Windows.Forms.GroupBox(); - btnOptionsLog = new System.Windows.Forms.Button(); - btnOptionsAdvanced = new System.Windows.Forms.Button(); - chkOptionsUseDarkMode = new System.Windows.Forms.CheckBox(); - chkAutoInstallUpdates = new System.Windows.Forms.CheckBox(); - btnStartStopService = new System.Windows.Forms.Button(); - btnElevationInfo = new System.Windows.Forms.Button(); - rbElevationService = new System.Windows.Forms.RadioButton(); - rbElevationProcess = new System.Windows.Forms.RadioButton(); - rbElevationAdmin = new System.Windows.Forms.RadioButton(); - label8 = new System.Windows.Forms.Label(); - rbElevationNone = new System.Windows.Forms.RadioButton(); - chkGdiScaling = new System.Windows.Forms.CheckBox(); - chkCheckForUpdates = new System.Windows.Forms.CheckBox(); - chkMinimizeToSystemTray = new System.Windows.Forms.CheckBox(); - chkMinimizeOnClose = new System.Windows.Forms.CheckBox(); - chkStartMinimized = new System.Windows.Forms.CheckBox(); - chkStartAfterLogin = new System.Windows.Forms.CheckBox(); tabInfo = new System.Windows.Forms.TabPage(); + tabOptions = new System.Windows.Forms.TabPage(); btnUpdate = new System.Windows.Forms.Button(); - mnuColorProfiles = new System.Windows.Forms.ContextMenuStrip(components); - miCreateHDRColorProfile = new System.Windows.Forms.ToolStripMenuItem(); - miCreateSDRColorProfile = new System.Windows.Forms.ToolStripMenuItem(); tcMain.SuspendLayout(); tabOptions.SuspendLayout(); - grpOptionsModules.SuspendLayout(); - grpMiscellaneousOptions.SuspendLayout(); - grpGeneralOptions.SuspendLayout(); - mnuColorProfiles.SuspendLayout(); SuspendLayout(); // // tcMain @@ -88,9 +53,6 @@ // // tabOptions // - tabOptions.Controls.Add(grpOptionsModules); - tabOptions.Controls.Add(grpMiscellaneousOptions); - tabOptions.Controls.Add(grpGeneralOptions); tabOptions.Location = new System.Drawing.Point(4, 24); tabOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); tabOptions.Name = "tabOptions"; @@ -100,353 +62,6 @@ tabOptions.Text = "Options"; tabOptions.UseVisualStyleBackColor = true; // - // grpOptionsModules - // - grpOptionsModules.Controls.Add(label1); - grpOptionsModules.Controls.Add(chkModules); - grpOptionsModules.Location = new System.Drawing.Point(11, 223); - grpOptionsModules.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - grpOptionsModules.Name = "grpOptionsModules"; - grpOptionsModules.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - grpOptionsModules.Size = new System.Drawing.Size(658, 131); - grpOptionsModules.TabIndex = 11; - grpOptionsModules.TabStop = false; - grpOptionsModules.Text = "Modules"; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new System.Drawing.Point(7, 19); - label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - label1.Name = "label1"; - label1.Size = new System.Drawing.Size(511, 15); - label1.TabIndex = 7; - label1.Text = "Here you can disable modules you do not want. A restart is required for a change to have effect."; - // - // chkModules - // - chkModules.ColumnWidth = 200; - chkModules.FormattingEnabled = true; - chkModules.Location = new System.Drawing.Point(7, 40); - chkModules.MultiColumn = true; - chkModules.Name = "chkModules"; - chkModules.Size = new System.Drawing.Size(507, 76); - chkModules.TabIndex = 0; - chkModules.ItemCheck += chkModules_ItemCheck; - // - // grpMiscellaneousOptions - // - grpMiscellaneousOptions.Controls.Add(btnOptionsColorProfiles); - grpMiscellaneousOptions.Controls.Add(btnSetShortcutScreenSaver); - grpMiscellaneousOptions.Controls.Add(label11); - grpMiscellaneousOptions.Controls.Add(edtBlankScreenSaverShortcut); - grpMiscellaneousOptions.Controls.Add(lblFixChromeFontsDescription); - grpMiscellaneousOptions.Controls.Add(chkFixChromeFonts); - grpMiscellaneousOptions.Location = new System.Drawing.Point(11, 360); - grpMiscellaneousOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - grpMiscellaneousOptions.Name = "grpMiscellaneousOptions"; - grpMiscellaneousOptions.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - grpMiscellaneousOptions.Size = new System.Drawing.Size(658, 131); - grpMiscellaneousOptions.TabIndex = 5; - grpMiscellaneousOptions.TabStop = false; - grpMiscellaneousOptions.Text = "Miscellaneous"; - // - // btnOptionsColorProfiles - // - btnOptionsColorProfiles.Location = new System.Drawing.Point(538, 17); - btnOptionsColorProfiles.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - btnOptionsColorProfiles.Name = "btnOptionsColorProfiles"; - btnOptionsColorProfiles.Size = new System.Drawing.Size(112, 27); - btnOptionsColorProfiles.TabIndex = 12; - btnOptionsColorProfiles.Text = "Color Profiles..."; - btnOptionsColorProfiles.UseVisualStyleBackColor = true; - btnOptionsColorProfiles.Click += btnOptionsColorProfiles_Click; - // - // btnSetShortcutScreenSaver - // - btnSetShortcutScreenSaver.Location = new System.Drawing.Point(181, 98); - btnSetShortcutScreenSaver.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - btnSetShortcutScreenSaver.Name = "btnSetShortcutScreenSaver"; - btnSetShortcutScreenSaver.Size = new System.Drawing.Size(40, 27); - btnSetShortcutScreenSaver.TabIndex = 10; - btnSetShortcutScreenSaver.Text = "Set"; - btnSetShortcutScreenSaver.UseVisualStyleBackColor = true; - btnSetShortcutScreenSaver.Click += btnSetShortcutScreenSaver_Click; - // - // label11 - // - label11.AutoSize = true; - label11.Location = new System.Drawing.Point(7, 80); - label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - label11.Name = "label11"; - label11.Size = new System.Drawing.Size(238, 15); - label11.TabIndex = 9; - label11.Text = "Set a shortcut to start the blank screensaver:"; - // - // edtBlankScreenSaverShortcut - // - edtBlankScreenSaverShortcut.Location = new System.Drawing.Point(7, 101); - edtBlankScreenSaverShortcut.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - edtBlankScreenSaverShortcut.Name = "edtBlankScreenSaverShortcut"; - edtBlankScreenSaverShortcut.ReadOnly = true; - edtBlankScreenSaverShortcut.Size = new System.Drawing.Size(165, 23); - edtBlankScreenSaverShortcut.TabIndex = 7; - edtBlankScreenSaverShortcut.KeyDown += edtShortcut_KeyDown; - edtBlankScreenSaverShortcut.KeyUp += edtShortcut_KeyUp; - // - // lblFixChromeFontsDescription - // - lblFixChromeFontsDescription.AutoSize = true; - lblFixChromeFontsDescription.Location = new System.Drawing.Point(4, 45); - lblFixChromeFontsDescription.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - lblFixChromeFontsDescription.Name = "lblFixChromeFontsDescription"; - lblFixChromeFontsDescription.Size = new System.Drawing.Size(427, 15); - lblFixChromeFontsDescription.TabIndex = 6; - lblFixChromeFontsDescription.Text = "This will add the parameter --disable-lcd-text to Chrome and requires elevation."; - // - // chkFixChromeFonts - // - chkFixChromeFonts.AutoSize = true; - chkFixChromeFonts.Location = new System.Drawing.Point(7, 22); - chkFixChromeFonts.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkFixChromeFonts.Name = "chkFixChromeFonts"; - chkFixChromeFonts.Size = new System.Drawing.Size(378, 19); - chkFixChromeFonts.TabIndex = 4; - chkFixChromeFonts.Text = "ClearType: fix bad fonts in Chrome (turn on grayscale anti-aliasing)"; - chkFixChromeFonts.UseVisualStyleBackColor = true; - chkFixChromeFonts.CheckedChanged += chkFixChromeFonts_CheckedChanged; - // - // grpGeneralOptions - // - grpGeneralOptions.Controls.Add(btnOptionsLog); - grpGeneralOptions.Controls.Add(btnOptionsAdvanced); - grpGeneralOptions.Controls.Add(chkOptionsUseDarkMode); - grpGeneralOptions.Controls.Add(chkAutoInstallUpdates); - grpGeneralOptions.Controls.Add(btnStartStopService); - grpGeneralOptions.Controls.Add(btnElevationInfo); - grpGeneralOptions.Controls.Add(rbElevationService); - grpGeneralOptions.Controls.Add(rbElevationProcess); - grpGeneralOptions.Controls.Add(rbElevationAdmin); - grpGeneralOptions.Controls.Add(label8); - grpGeneralOptions.Controls.Add(rbElevationNone); - grpGeneralOptions.Controls.Add(chkGdiScaling); - grpGeneralOptions.Controls.Add(chkCheckForUpdates); - grpGeneralOptions.Controls.Add(chkMinimizeToSystemTray); - grpGeneralOptions.Controls.Add(chkMinimizeOnClose); - grpGeneralOptions.Controls.Add(chkStartMinimized); - grpGeneralOptions.Controls.Add(chkStartAfterLogin); - grpGeneralOptions.Location = new System.Drawing.Point(7, 6); - grpGeneralOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - grpGeneralOptions.Name = "grpGeneralOptions"; - grpGeneralOptions.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - grpGeneralOptions.Size = new System.Drawing.Size(662, 211); - grpGeneralOptions.TabIndex = 2; - grpGeneralOptions.TabStop = false; - grpGeneralOptions.Text = "General"; - // - // btnOptionsLog - // - btnOptionsLog.Location = new System.Drawing.Point(103, 172); - btnOptionsLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - btnOptionsLog.Name = "btnOptionsLog"; - btnOptionsLog.Size = new System.Drawing.Size(88, 27); - btnOptionsLog.TabIndex = 68; - btnOptionsLog.Text = "Logging..."; - btnOptionsLog.UseVisualStyleBackColor = true; - btnOptionsLog.Click += btnOptionsLog_Click; - // - // btnOptionsAdvanced - // - btnOptionsAdvanced.Location = new System.Drawing.Point(7, 172); - btnOptionsAdvanced.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - btnOptionsAdvanced.Name = "btnOptionsAdvanced"; - btnOptionsAdvanced.Size = new System.Drawing.Size(88, 27); - btnOptionsAdvanced.TabIndex = 11; - btnOptionsAdvanced.Text = "Advanced..."; - btnOptionsAdvanced.UseVisualStyleBackColor = true; - btnOptionsAdvanced.Click += btnOptionsAdvanced_Click; - // - // chkOptionsUseDarkMode - // - chkOptionsUseDarkMode.AutoSize = true; - chkOptionsUseDarkMode.Location = new System.Drawing.Point(216, 47); - chkOptionsUseDarkMode.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkOptionsUseDarkMode.Name = "chkOptionsUseDarkMode"; - chkOptionsUseDarkMode.Size = new System.Drawing.Size(164, 19); - chkOptionsUseDarkMode.TabIndex = 67; - chkOptionsUseDarkMode.Text = "Dark Mode (experimental)"; - chkOptionsUseDarkMode.UseVisualStyleBackColor = true; - chkOptionsUseDarkMode.CheckedChanged += chkOptionsUseDarkMode_CheckedChanged; - // - // chkAutoInstallUpdates - // - chkAutoInstallUpdates.AutoSize = true; - chkAutoInstallUpdates.Location = new System.Drawing.Point(7, 147); - chkAutoInstallUpdates.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkAutoInstallUpdates.Name = "chkAutoInstallUpdates"; - chkAutoInstallUpdates.Size = new System.Drawing.Size(179, 19); - chkAutoInstallUpdates.TabIndex = 66; - chkAutoInstallUpdates.Text = "Automatically install updates"; - chkAutoInstallUpdates.UseVisualStyleBackColor = true; - chkAutoInstallUpdates.CheckedChanged += chkAutoInstallUpdates_CheckedChanged; - // - // btnStartStopService - // - btnStartStopService.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; - btnStartStopService.Location = new System.Drawing.Point(614, 129); - btnStartStopService.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - btnStartStopService.Name = "btnStartStopService"; - btnStartStopService.Size = new System.Drawing.Size(40, 27); - btnStartStopService.TabIndex = 65; - btnStartStopService.Text = "Start"; - btnStartStopService.UseVisualStyleBackColor = true; - btnStartStopService.Click += btnStartStopService_Click; - // - // btnElevationInfo - // - btnElevationInfo.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; - btnElevationInfo.Location = new System.Drawing.Point(329, 67); - btnElevationInfo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - btnElevationInfo.Name = "btnElevationInfo"; - btnElevationInfo.Size = new System.Drawing.Size(22, 27); - btnElevationInfo.TabIndex = 64; - btnElevationInfo.Text = "?"; - btnElevationInfo.UseVisualStyleBackColor = true; - btnElevationInfo.Click += btnElevationInfo_Click; - // - // rbElevationService - // - rbElevationService.AutoSize = true; - rbElevationService.Location = new System.Drawing.Point(216, 133); - rbElevationService.Name = "rbElevationService"; - rbElevationService.Size = new System.Drawing.Size(136, 19); - rbElevationService.TabIndex = 63; - rbElevationService.TabStop = true; - rbElevationService.Tag = "2"; - rbElevationService.Text = "Use Windows Service"; - rbElevationService.UseVisualStyleBackColor = true; - rbElevationService.CheckedChanged += rbElevationNone_CheckedChanged; - // - // rbElevationProcess - // - rbElevationProcess.AutoSize = true; - rbElevationProcess.Location = new System.Drawing.Point(216, 154); - rbElevationProcess.Name = "rbElevationProcess"; - rbElevationProcess.Size = new System.Drawing.Size(189, 19); - rbElevationProcess.TabIndex = 62; - rbElevationProcess.TabStop = true; - rbElevationProcess.Tag = "3"; - rbElevationProcess.Text = "Use dedicated elevated process"; - rbElevationProcess.UseVisualStyleBackColor = true; - rbElevationProcess.CheckedChanged += rbElevationNone_CheckedChanged; - // - // rbElevationAdmin - // - rbElevationAdmin.AutoSize = true; - rbElevationAdmin.Location = new System.Drawing.Point(216, 112); - rbElevationAdmin.Name = "rbElevationAdmin"; - rbElevationAdmin.Size = new System.Drawing.Size(97, 19); - rbElevationAdmin.TabIndex = 61; - rbElevationAdmin.TabStop = true; - rbElevationAdmin.Tag = "1"; - rbElevationAdmin.Text = "Run as admin"; - rbElevationAdmin.UseVisualStyleBackColor = true; - rbElevationAdmin.CheckedChanged += rbElevationNone_CheckedChanged; - // - // label8 - // - label8.AutoSize = true; - label8.Location = new System.Drawing.Point(216, 73); - label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - label8.Name = "label8"; - label8.Size = new System.Drawing.Size(105, 15); - label8.TabIndex = 60; - label8.Text = "Elevation-method:"; - // - // rbElevationNone - // - rbElevationNone.AutoSize = true; - rbElevationNone.Location = new System.Drawing.Point(216, 91); - rbElevationNone.Name = "rbElevationNone"; - rbElevationNone.Size = new System.Drawing.Size(54, 19); - rbElevationNone.TabIndex = 10; - rbElevationNone.TabStop = true; - rbElevationNone.Tag = "0"; - rbElevationNone.Text = "None"; - rbElevationNone.UseVisualStyleBackColor = true; - rbElevationNone.CheckedChanged += rbElevationNone_CheckedChanged; - // - // chkGdiScaling - // - chkGdiScaling.AutoSize = true; - chkGdiScaling.Location = new System.Drawing.Point(216, 22); - chkGdiScaling.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkGdiScaling.Name = "chkGdiScaling"; - chkGdiScaling.Size = new System.Drawing.Size(197, 19); - chkGdiScaling.TabIndex = 7; - chkGdiScaling.Text = "Use GDI Scaling (requires restart)"; - chkGdiScaling.UseVisualStyleBackColor = true; - chkGdiScaling.CheckedChanged += chkGdiScaling_CheckedChanged; - // - // chkCheckForUpdates - // - chkCheckForUpdates.AutoSize = true; - chkCheckForUpdates.Location = new System.Drawing.Point(7, 122); - chkCheckForUpdates.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkCheckForUpdates.Name = "chkCheckForUpdates"; - chkCheckForUpdates.Size = new System.Drawing.Size(197, 19); - chkCheckForUpdates.TabIndex = 6; - chkCheckForUpdates.Text = "Automatically check for updates"; - chkCheckForUpdates.UseVisualStyleBackColor = true; - chkCheckForUpdates.CheckedChanged += chkCheckForUpdates_CheckedChanged; - // - // chkMinimizeToSystemTray - // - chkMinimizeToSystemTray.AutoSize = true; - chkMinimizeToSystemTray.Location = new System.Drawing.Point(7, 97); - chkMinimizeToSystemTray.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkMinimizeToSystemTray.Name = "chkMinimizeToSystemTray"; - chkMinimizeToSystemTray.Size = new System.Drawing.Size(152, 19); - chkMinimizeToSystemTray.TabIndex = 5; - chkMinimizeToSystemTray.Text = "Minimize to system tray"; - chkMinimizeToSystemTray.UseVisualStyleBackColor = true; - chkMinimizeToSystemTray.CheckedChanged += chkMinimizeToSystemTray_CheckedChanged; - // - // chkMinimizeOnClose - // - chkMinimizeOnClose.AutoSize = true; - chkMinimizeOnClose.Location = new System.Drawing.Point(7, 72); - chkMinimizeOnClose.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkMinimizeOnClose.Name = "chkMinimizeOnClose"; - chkMinimizeOnClose.Size = new System.Drawing.Size(122, 19); - chkMinimizeOnClose.TabIndex = 4; - chkMinimizeOnClose.Text = "Minimize on close"; - chkMinimizeOnClose.UseVisualStyleBackColor = true; - chkMinimizeOnClose.CheckedChanged += chkMinimizeOnClose_CheckedChanged; - // - // chkStartMinimized - // - chkStartMinimized.AutoSize = true; - chkStartMinimized.Location = new System.Drawing.Point(7, 47); - chkStartMinimized.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkStartMinimized.Name = "chkStartMinimized"; - chkStartMinimized.Size = new System.Drawing.Size(109, 19); - chkStartMinimized.TabIndex = 3; - chkStartMinimized.Text = "Start minimized"; - chkStartMinimized.UseVisualStyleBackColor = true; - // - // chkStartAfterLogin - // - chkStartAfterLogin.AutoSize = true; - chkStartAfterLogin.Location = new System.Drawing.Point(7, 22); - chkStartAfterLogin.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - chkStartAfterLogin.Name = "chkStartAfterLogin"; - chkStartAfterLogin.Size = new System.Drawing.Size(183, 19); - chkStartAfterLogin.TabIndex = 2; - chkStartAfterLogin.Text = "Automatically start after login"; - chkStartAfterLogin.UseVisualStyleBackColor = true; - chkStartAfterLogin.CheckedChanged += chkStartAfterLogin_CheckedChanged; - // // tabInfo // tabInfo.Location = new System.Drawing.Point(4, 24); @@ -473,27 +88,6 @@ btnUpdate.Visible = false; btnUpdate.Click += btnUpdate_Click; // - // mnuColorProfiles - // - mnuColorProfiles.ImageScalingSize = new System.Drawing.Size(20, 20); - mnuColorProfiles.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { miCreateHDRColorProfile, miCreateSDRColorProfile }); - mnuColorProfiles.Name = "mnuLgButtons"; - mnuColorProfiles.Size = new System.Drawing.Size(214, 70); - // - // miCreateHDRColorProfile - // - miCreateHDRColorProfile.Name = "miCreateHDRColorProfile"; - miCreateHDRColorProfile.Size = new System.Drawing.Size(213, 22); - miCreateHDRColorProfile.Text = "Create HDR Color Profile..."; - miCreateHDRColorProfile.Click += miCreateHDRColorProfile_Click; - // - // miCreateSDRColorProfile - // - miCreateSDRColorProfile.Name = "miCreateSDRColorProfile"; - miCreateSDRColorProfile.Size = new System.Drawing.Size(213, 22); - miCreateSDRColorProfile.Text = "Create SDR Color Profile..."; - miCreateSDRColorProfile.Click += miCreateSDRColorProfile_Click; - // // MainForm // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -518,13 +112,6 @@ Resize += MainForm_Resize; tcMain.ResumeLayout(false); tabOptions.ResumeLayout(false); - grpOptionsModules.ResumeLayout(false); - grpOptionsModules.PerformLayout(); - grpMiscellaneousOptions.ResumeLayout(false); - grpMiscellaneousOptions.PerformLayout(); - grpGeneralOptions.ResumeLayout(false); - grpGeneralOptions.PerformLayout(); - mnuColorProfiles.ResumeLayout(false); ResumeLayout(false); } @@ -532,39 +119,8 @@ private System.Windows.Forms.TabControl tcMain; private System.Windows.Forms.TabPage tabOptions; - private System.Windows.Forms.GroupBox grpGeneralOptions; - private System.Windows.Forms.CheckBox chkStartMinimized; - private System.Windows.Forms.CheckBox chkStartAfterLogin; private System.Windows.Forms.TabPage tabInfo; - private System.Windows.Forms.GroupBox grpMiscellaneousOptions; - private System.Windows.Forms.CheckBox chkFixChromeFonts; - private System.Windows.Forms.Label lblFixChromeFontsDescription; - private System.Windows.Forms.Button btnSetShortcutScreenSaver; - private System.Windows.Forms.Label label11; - private System.Windows.Forms.TextBox edtBlankScreenSaverShortcut; - private System.Windows.Forms.CheckBox chkMinimizeOnClose; - private System.Windows.Forms.CheckBox chkMinimizeToSystemTray; - private System.Windows.Forms.CheckBox chkCheckForUpdates; - private System.Windows.Forms.CheckBox chkGdiScaling; - private System.Windows.Forms.RadioButton rbElevationService; - private System.Windows.Forms.RadioButton rbElevationProcess; - private System.Windows.Forms.RadioButton rbElevationAdmin; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.RadioButton rbElevationNone; - private System.Windows.Forms.Button btnElevationInfo; - private System.Windows.Forms.Button btnStartStopService; - private System.Windows.Forms.CheckBox chkAutoInstallUpdates; private System.Windows.Forms.Button btnUpdate; - private System.Windows.Forms.GroupBox grpOptionsModules; - private System.Windows.Forms.CheckedListBox chkModules; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.CheckBox chkOptionsUseDarkMode; - private System.Windows.Forms.Button btnOptionsAdvanced; - private System.Windows.Forms.Button btnOptionsLog; - private System.Windows.Forms.Button btnOptionsColorProfiles; - private System.Windows.Forms.ContextMenuStrip mnuColorProfiles; - private System.Windows.Forms.ToolStripMenuItem miCreateHDRColorProfile; - private System.Windows.Forms.ToolStripMenuItem miCreateSDRColorProfile; } } diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 55eeb5c..3187676 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -11,7 +11,6 @@ using ColorControl.Shared.Contracts; using ColorControl.Shared.Forms; using ColorControl.Shared.Native; using ColorControl.Shared.Services; -using ColorControl.XForms; using Linearstar.Windows.RawInput; using Microsoft.Extensions.DependencyInjection; using NLog; @@ -34,7 +33,7 @@ namespace ColorControl { private static bool SystemShutdown = false; private static bool EndSession = false; - private static int SHORTCUTID_SCREENSAVER = -100; + public static int SHORTCUTID_SCREENSAVER = -100; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly PowerEventDispatcher _powerEventDispatcher; @@ -42,11 +41,12 @@ namespace ColorControl private readonly IServiceProvider _serviceProvider; private readonly WinApiAdminService _winApiAdminService; private readonly WinApiService _winApiService; + private readonly ElevationService _elevationService; private string _dataDir; private NvPanel _nvPanel; - private NotifyIcon _trayIcon; + public NotifyIcon _trayIcon; private bool _initialized = false; private Config _config; private bool _setVisibleCalled = false; @@ -78,7 +78,7 @@ namespace ColorControl private Dictionary> _modules = new(); public MainForm(AppContextProvider appContextProvider, PowerEventDispatcher powerEventDispatcher, ServiceManager serviceManager, - IServiceProvider serviceProvider, WinApiAdminService winApiAdminService, WinApiService winApiService) + IServiceProvider serviceProvider, WinApiAdminService winApiAdminService, WinApiService winApiService, ElevationService elevationService) { InitializeComponent(); @@ -92,6 +92,7 @@ namespace ColorControl _serviceProvider = serviceProvider; _winApiAdminService = winApiAdminService; _winApiService = winApiService; + _elevationService = elevationService; _dataDir = Program.DataDir; _config = Program.Config; @@ -144,23 +145,15 @@ namespace ColorControl _trayIcon.ContextMenuStrip.Opened += trayIconContextMenu_Popup; _trayIcon.BalloonTipClicked += trayIconBalloonTip_Clicked; - chkStartAfterLogin.Checked = _winApiService.TaskExists(Program.TS_TASKNAME); - - chkFixChromeFonts.Enabled = _winApiService.IsChromeInstalled(); - if (chkFixChromeFonts.Enabled) - { - var fixInstalled = _winApiService.IsChromeFixInstalled(); - if (_config.FixChromeFonts && !fixInstalled) - { - _winApiAdminService.InstallChromeFix(true, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); - } - chkFixChromeFonts.Checked = _winApiService.IsChromeFixInstalled(); - } - InitShortcut(SHORTCUTID_SCREENSAVER, _config.ScreenSaverShortcut, StartScreenSaver); InitModules(); - UpdateServiceInfo(); + + // Auto-apply fix if desired but not currently installed + if (_config.FixChromeFonts && _winApiService.IsChromeInstalled() && !_winApiService.IsChromeFixInstalled()) + { + _winApiAdminService.InstallChromeFix(true, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); + } _screenStateNotify = WinApi.RegisterPowerSettingNotification(Handle, ref Utils.GUID_CONSOLE_DISPLAY_STATE, 0); @@ -236,31 +229,6 @@ namespace ColorControl _serviceManager.NvService?.InstallEventHandlers(); } - private void UpdateServiceInfo() - { - var text = "Use Windows Service"; - btnStartStopService.Enabled = true; - - if (_winApiService.IsServiceRunning()) - { - text += " (running)"; - btnStartStopService.Text = "Stop"; - } - else if (_winApiService.IsServiceInstalled()) - { - text += " (installed, not running)"; - btnStartStopService.Text = "Start"; - } - else - { - text += " (not installed)"; - btnStartStopService.Text = "Start"; - btnStartStopService.Enabled = false; - } - - rbElevationService.Text = text; - } - private UserControl InitNvService() { try @@ -577,11 +545,6 @@ namespace ColorControl Process.Start("explorer.exe", screenSaver); } - private void edtShortcut_KeyDown(object sender, KeyEventArgs e) - { - ((TextBox)sender).Text = KeyboardShortcutManager.FormatKeyboardShortcut(e); - } - private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { // Hide tray icon, otherwise it will remain shown until user mouses over it @@ -615,34 +578,8 @@ namespace ColorControl } } - private void chkStartAfterLogin_CheckedChanged(object sender, EventArgs e) - { - if (!_initialized) - { - return; - } - var enabled = chkStartAfterLogin.Checked; - RegisterScheduledTask(enabled); - - rbElevationAdmin.Enabled = enabled; - if (!enabled && rbElevationAdmin.Checked) - { - rbElevationNone.Checked = true; - } - } - private void LoadConfig() { - chkStartMinimized.Checked = _config.StartMinimized; - chkMinimizeOnClose.Checked = _config.MinimizeOnClose; - chkMinimizeToSystemTray.Checked = _config.MinimizeToTray; - chkCheckForUpdates.Checked = _config.CheckForUpdates; - chkAutoInstallUpdates.Checked = _config.AutoInstallUpdates; - chkAutoInstallUpdates.Enabled = _config.CheckForUpdates && _config.ElevationMethod == ElevationMethod.UseService; - edtBlankScreenSaverShortcut.Text = _config.ScreenSaverShortcut; - chkGdiScaling.Checked = _config.UseGdiScaling; - chkOptionsUseDarkMode.Checked = _config.UseDarkMode; - _skipResize = true; try { @@ -657,7 +594,6 @@ namespace ColorControl private void SaveConfig() { - _config.StartMinimized = chkStartMinimized.Checked; if (WindowState != FormWindowState.Minimized) { _config.FormWidth = Width; @@ -710,7 +646,7 @@ Do you want to install and start the Windows Service now? You can always change NOTE: installing the service may cause a User Account Control popup."); if (result == DialogResult.Yes) { - SetElevationMethod(ElevationMethod.UseService); + _elevationService.SetElevationMethod(ElevationMethod.UseService); } _config.ElevationMethodAsked = true; @@ -736,11 +672,6 @@ NOTE: installing the service may cause a User Account Control popup."); } } - private void edtShortcut_KeyUp(object sender, KeyEventArgs e) - { - KeyboardShortcutManager.HandleKeyboardShortcutUp(e); - } - private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { InitSelectedTab(); @@ -764,32 +695,17 @@ NOTE: installing the service may cause a User Account Control popup."); private void InitOptionsTab() { - if (chkModules.Items.Count == 0) + if (tabInfo.Controls.Count > 0) { - foreach (var module in _config.Modules) - { - chkModules.Items.Add(module.DisplayName, module.IsActive); - } + return; } - _initialized = false; - try - { - var _ = _config.ElevationMethod switch - { - ElevationMethod.None => rbElevationNone.Checked = true, - ElevationMethod.RunAsAdmin => rbElevationAdmin.Checked = true, - ElevationMethod.UseService => rbElevationService.Checked = true, - ElevationMethod.UseElevatedProcess => rbElevationProcess.Checked = true, - _ => false - }; - } - finally - { - _initialized = true; - } + var control = _serviceProvider.GetRequiredService(); + control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - UpdateServiceInfo(); + tabOptions.Controls.Add(control); + + control.Size = tabInfo.ClientSize; } private void InitInfoTab() @@ -811,7 +727,7 @@ NOTE: installing the service may cause a User Account Control popup."); { menu.DropDownItems.Clear(); - foreach (var preset in presets) + foreach (var preset in presets.OrderBy(p => p.name)) { var name = preset.GetTextForMenuItem(); var keys = Keys.None; @@ -859,7 +775,7 @@ NOTE: installing the service may cause a User Account Control popup."); _nvTrayMenu.Visible = _serviceManager.NvService != null; if (_nvTrayMenu.Visible) { - var presets = _serviceManager.NvService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate || x.applyResolution || x.applyDriverSettings); + var presets = _serviceManager.NvService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate || x.applyResolution || x.applyDriverSettings || x.applyOther || x.applyOverclocking || x.ApplyColorEnhancements || x.applyHdmiSettings); UpdateTrayMenu(_nvTrayMenu, presets, TrayMenuItemNv_Click); } @@ -925,29 +841,6 @@ NOTE: installing the service may cause a User Account Control popup."); await _samsungPanel?.ApplyPreset(preset); } - private void btnRefreshNVIDIAInfo_Click(object sender, EventArgs e) - { - } - - private void btnSetShortcutScreenSaver_Click(object sender, EventArgs e) - { - var shortcut = edtBlankScreenSaverShortcut.Text.Trim(); - - if (!KeyboardShortcutManager.ValidateShortcut(shortcut)) - { - return; - } - - _config.ScreenSaverShortcut = shortcut; - - KeyboardShortcutManager.RegisterShortcut(SHORTCUTID_SCREENSAVER, shortcut); - } - - private void chkMinimizeOnClose_CheckedChanged(object sender, EventArgs e) - { - _config.MinimizeOnClose = chkMinimizeOnClose.Checked; - } - private void MainForm_Activated(object sender, EventArgs e) { if (tcMain.SelectedTab?.Controls.Count > 0 && tcMain.SelectedTab.Controls[0] is IModulePanel panel) @@ -1116,29 +1009,6 @@ NOTE: installing the service may cause a User Account Control popup."); (_serviceManager.LgService?.GetPresets().Any(x => x.id != presetId && shortcut.Equals(x.shortcut)) ?? false); } - private void chkMinimizeToSystemTray_CheckedChanged(object sender, EventArgs e) - { - if (_initialized) - { - _config.MinimizeToTray = chkMinimizeToSystemTray.Checked; - _trayIcon.Visible = _config.MinimizeToTray; - } - } - - private void chkCheckForUpdates_CheckedChanged(object sender, EventArgs e) - { - if (_initialized) - { - _config.CheckForUpdates = chkCheckForUpdates.Checked; - chkAutoInstallUpdates.Enabled = _config.CheckForUpdates && _config.ElevationMethod == ElevationMethod.UseService; - } - } - - private void chkGdiScaling_CheckedChanged(object sender, EventArgs e) - { - _config.UseGdiScaling = chkGdiScaling.Checked; - } - private void MainForm_ResizeBegin(object sender, EventArgs e) { SuspendLayout(); @@ -1149,143 +1019,6 @@ NOTE: installing the service may cause a User Account Control popup."); ResumeLayout(true); } - private void rbElevationNone_CheckedChanged(object sender, EventArgs e) - { - if (!_initialized) - { - return; - } - - - if (sender is not RadioButton button || !button.Checked) - { - return; - } - - SetElevationMethod((ElevationMethod)Utils.ParseInt((string)button.Tag)); - } - - private void SetElevationMethod(ElevationMethod elevationMethod) - { - _config.ElevationMethod = elevationMethod; - - var _ = _config.ElevationMethod switch - { - ElevationMethod.None => SetElevationMethodNone(), - ElevationMethod.RunAsAdmin => SetElevationMethodRunAsAdmin(), - ElevationMethod.UseService => SetElevationMethodUseService(), - ElevationMethod.UseElevatedProcess => SetElevationMethodUseElevatedProcess(), - _ => true - }; - - UpdateServiceInfo(); - } - - private bool SetElevationMethodNone() - { - if (chkStartAfterLogin.Enabled) - { - RegisterScheduledTask(); - } - - _winApiAdminService.UninstallService(); - - return true; - } - - private bool SetElevationMethodRunAsAdmin() - { - if (chkStartAfterLogin.Enabled) - { - RegisterScheduledTask(false); - RegisterScheduledTask(); - } - - _winApiAdminService.UninstallService(); - - return true; - } - - private bool SetElevationMethodUseService() - { - _winApiAdminService.InstallService(); - - if (_winApiService.IsServiceInstalled()) - { - MessageForms.InfoOk("Service installed successfully."); - return true; - } - - MessageForms.ErrorOk("Service could not be installed. Check the logs."); - - return false; - } - - private bool SetElevationMethodUseElevatedProcess() - { - if (chkStartAfterLogin.Enabled) - { - RegisterScheduledTask(); - } - - _winApiAdminService.UninstallService(); - - return true; - } - - private void RegisterScheduledTask(bool enabled = true) - { - _winApiAdminService.RegisterTask(Program.TS_TASKNAME, enabled, _config.ElevationMethod == ElevationMethod.RunAsAdmin ? Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest : Microsoft.Win32.TaskScheduler.TaskRunLevel.LUA); - } - - private void btnElevationInfo_Click(object sender, EventArgs e) - { - MessageForms.InfoOk(Utils.ELEVATION_MSG + @$" - -NOTE: if ColorControl itself already runs as administrator this is indicated in the title: ColorControl {Application.ProductVersion} (administrator). - -Currently ColorControl is {(_winApiService.IsAdministrator() ? "" : "not ")}running as administrator. -"); - } - - private async void btnStartStopService_Click(object sender, EventArgs e) - { - btnStartStopService.Enabled = false; - try - { - var start = btnStartStopService.Text == "Start"; - - if (start) - { - _winApiAdminService.StartService(); - } - else - { - _winApiAdminService.StopService(); - } - - var wait = 1500; - - while (wait > 0) - { - await Task.Delay(100); - - if (start == _winApiService.IsServiceRunning()) - { - break; - } - - wait -= 100; - } - } - finally - { - btnStartStopService.Enabled = true; - } - - UpdateServiceInfo(); - } - private async void MainForm_Click(object sender, EventArgs e) { //_powerEventDispatcher.SendEvent(PowerEventDispatcher.Event_Shutdown); @@ -1298,11 +1031,7 @@ Currently ColorControl is {(_winApiService.IsAdministrator() ? "" : "not ")}runn _serviceManager.NvService?.TestResolution(); } - private async Task Test() - { - } - - private void SetTheme(bool toDark) + public void SetTheme(bool toDark) { this.UpdateTheme(toDark); @@ -1315,14 +1044,6 @@ Currently ColorControl is {(_winApiService.IsAdministrator() ? "" : "not ")}runn InitSelectedTab(); } - private void chkAutoInstallUpdates_CheckedChanged(object sender, EventArgs e) - { - if (_initialized) - { - _config.AutoInstallUpdates = chkAutoInstallUpdates.Checked; - } - } - private void btnUpdate_Click(object sender, EventArgs e) { if (_downloadUrl != null) @@ -1341,18 +1062,6 @@ Currently ColorControl is {(_winApiService.IsAdministrator() ? "" : "not ")}runn _trayIcon.Visible = false; } - private void chkFixChromeFonts_CheckedChanged(object sender, EventArgs e) - { - if (_initialized) - { - _config.FixChromeFonts = chkFixChromeFonts.Checked; - - var folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - - _winApiAdminService.InstallChromeFix(chkFixChromeFonts.Checked, folder); - } - } - protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if ((keyData == (Keys.Control | Keys.PageUp) || keyData == (Keys.Control | Keys.PageDown)) && IsShortcutControlFocused()) @@ -1370,95 +1079,5 @@ Currently ColorControl is {(_winApiService.IsAdministrator() ? "" : "not ")}runn } return base.ProcessCmdKey(ref msg, keyData); } - - private void chkOptionsUseDarkMode_CheckedChanged(object sender, EventArgs e) - { - if (!_initialized) - { - return; - } - - _config.UseDarkMode = chkOptionsUseDarkMode.Checked; - - SetTheme(_config.UseDarkMode); - } - - private void btnOptionsAdvanced_Click(object sender, EventArgs e) - { - var processPollingIntervalField = new FieldDefinition - { - FieldType = FieldType.Numeric, - Label = "Polling interval of process monitor (milliseconds).", - SubLabel = "Decreasing this delay may execute triggered presets sooner but can cause a higher CPU load", - MinValue = 50, - MaxValue = 5000, - Value = _config.ProcessMonitorPollingInterval - }; - var useRawInputField = new FieldDefinition - { - FieldType = FieldType.CheckBox, - Label = "Use Raw Input for shortcuts (hot keys)", - SubLabel = "This enables shortcuts to work during applications/games that block certain keys (like WinKey or Control). NOTE: if the application in the foreground runs with higher privileges than ColorControl, Raw Input does not work and normal hot keys are used", - Value = _config.UseRawInput - }; - var setMinTmlAndMaxTmlField = new FieldDefinition - { - FieldType = FieldType.CheckBox, - Label = "Set MinTML and MaxTML when applying color profiles", - SubLabel = "When this is enabled MinTML and MaxTML will be automatically be set to respectively the minimum luminance and the maximum luminance of the color profile", - Value = _config.SetMinTmlAndMaxTml - }; - - var values = MessageForms.ShowDialog("Advanced settings", new[] { processPollingIntervalField, useRawInputField, setMinTmlAndMaxTmlField }); - - if (values?.Any() != true) - { - return; - } - - _config.ProcessMonitorPollingInterval = processPollingIntervalField.ValueAsInt; - _config.UseRawInput = useRawInputField.ValueAsBool; - _config.SetMinTmlAndMaxTml = setMinTmlAndMaxTmlField.ValueAsBool; - - KeyboardShortcutManager.SetUseRawInput(_config.UseRawInput); - } - - private void btnOptionsLog_Click(object sender, EventArgs e) - { - LogWindow.CreateAndShow(); - } - - private void chkModules_ItemCheck(object sender, ItemCheckEventArgs e) - { - if (chkModules.Items.Count != _config.Modules.Count) - { - return; - } - - var index = e.Index; - - if (index < 0) - { - return; - } - - var module = _config.Modules[index]; - module.IsActive = e.NewValue == CheckState.Checked; - } - - private void miCreateHDRColorProfile_Click(object sender, EventArgs e) - { - ColorProfileWindow.CreateAndShow(); - } - - private void btnOptionsColorProfiles_Click(object sender, EventArgs e) - { - mnuColorProfiles.ShowCustom(btnOptionsColorProfiles); - } - - private void miCreateSDRColorProfile_Click(object sender, EventArgs e) - { - ColorProfileWindow.CreateAndShow(isHDR: false); - } } } \ No newline at end of file diff --git a/ColorControl/Program.cs b/ColorControl/Program.cs index 07b10af..fc84fbb 100644 --- a/ColorControl/Program.cs +++ b/ColorControl/Program.cs @@ -259,6 +259,8 @@ namespace ColorControl services.AddTransient(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); }); } private static async Task RunService(string[] args) @@ -335,5 +337,15 @@ namespace ColorControl MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } + + internal static void SetTheme(bool useDarkMode) + { + _mainForm?.SetTheme(useDarkMode); + } + + internal static NotifyIcon GetNotifyIcon() + { + return _mainForm?._trayIcon; + } } } diff --git a/ColorControl/Services/Common/ElevationService.cs b/ColorControl/Services/Common/ElevationService.cs new file mode 100644 index 0000000..0d8c0c7 --- /dev/null +++ b/ColorControl/Services/Common/ElevationService.cs @@ -0,0 +1,94 @@ +using ColorControl.Shared.Contracts; +using ColorControl.Shared.Forms; +using ColorControl.Shared.Services; + +namespace ColorControl.Services.Common; + +public class ElevationService +{ + private readonly WinApiService _winApiService; + private readonly WinApiAdminService _winApiAdminService; + private readonly AppContextProvider _appContextProvider; + + private readonly Config _config; + + public ElevationService(WinApiService winApiService, WinApiAdminService winApiAdminService, AppContextProvider appContextProvider) + { + _winApiService = winApiService; + _winApiAdminService = winApiAdminService; + _appContextProvider = appContextProvider; + + _config = appContextProvider.GetAppContext().Config; + } + + public void SetElevationMethod(ElevationMethod elevationMethod, bool startAfterLoginChecked = false) + { + _config.ElevationMethod = elevationMethod; + + var _ = _config.ElevationMethod switch + { + ElevationMethod.None => SetElevationMethodNone(startAfterLoginChecked), + ElevationMethod.RunAsAdmin => SetElevationMethodRunAsAdmin(startAfterLoginChecked), + ElevationMethod.UseService => SetElevationMethodUseService(), + ElevationMethod.UseElevatedProcess => SetElevationMethodUseElevatedProcess(startAfterLoginChecked), + _ => true + }; + } + + public void RegisterScheduledTask(bool enabled = true) + { + _winApiAdminService.RegisterTask(Program.TS_TASKNAME, enabled, _config.ElevationMethod == ElevationMethod.RunAsAdmin ? Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest : Microsoft.Win32.TaskScheduler.TaskRunLevel.LUA); + } + + private bool SetElevationMethodNone(bool startAfterLoginChecked = false) + { + if (startAfterLoginChecked) + { + RegisterScheduledTask(); + } + + _winApiAdminService.UninstallService(); + + return true; + } + + private bool SetElevationMethodRunAsAdmin(bool startAfterLoginChecked = false) + { + if (startAfterLoginChecked) + { + RegisterScheduledTask(false); + RegisterScheduledTask(); + } + + _winApiAdminService.UninstallService(); + + return true; + } + + private bool SetElevationMethodUseService() + { + _winApiAdminService.InstallService(); + + if (_winApiService.IsServiceInstalled()) + { + MessageForms.InfoOk("Service installed successfully."); + return true; + } + + MessageForms.ErrorOk("Service could not be installed. Check the logs."); + + return false; + } + + private bool SetElevationMethodUseElevatedProcess(bool startAfterLoginChecked = false) + { + if (startAfterLoginChecked) + { + RegisterScheduledTask(); + } + + _winApiAdminService.UninstallService(); + + return true; + } +} diff --git a/ColorControl/Services/Common/PresetBase.cs b/ColorControl/Services/Common/PresetBase.cs index fdd0bb2..fa47a87 100644 --- a/ColorControl/Services/Common/PresetBase.cs +++ b/ColorControl/Services/Common/PresetBase.cs @@ -96,7 +96,7 @@ namespace ColorControl.Services.Common } else { - active = context.Triggers.Contains(Trigger); + active = active && context.Triggers.Contains(Trigger); } return active; diff --git a/ColorControl/Services/LG/LgDevice.cs b/ColorControl/Services/LG/LgDevice.cs index 594c8bf..e7f55af 100644 --- a/ColorControl/Services/LG/LgDevice.cs +++ b/ColorControl/Services/LG/LgDevice.cs @@ -38,6 +38,7 @@ namespace ColorControl.Services.LG public int Contrast { get; set; } public int Brightness { get; set; } public int Color { get; set; } + public int Volume { get; set; } } public enum PowerState @@ -199,7 +200,7 @@ namespace ColorControl.Services.LG AddGenericPictureAction("blackLevel", typeof(BlackLevel), title: "HDMI Black Level"); AddGenericPictureAction("dolbyPrecisionDetail", typeof(OffToOn), title: "Dolby Precision Detail", fromModelYear: ModelYear.Series2022); - AddGenericPictureAction("ai_Brightness", typeof(OffToOn), title: "AI Brightness", fromModelYear: ModelYear.Series2021, category: "aiPicture"); + AddGenericPictureAction("ai_Brightness", typeof(OffToOn), title: "AI Brightness", fromModelYear: ModelYear.Series2019, category: "aiPicture"); AddGenericPictureAction("ai_Genre", typeof(OffToOn), title: "AI Genre Selection", fromModelYear: ModelYear.Series2021, category: "aiPicture"); AddGenericPictureAction("ai_Picture", typeof(OffToOn), title: "AI Picture Pro", fromModelYear: ModelYear.Series2021, category: "aiPicture"); @@ -225,6 +226,8 @@ namespace ColorControl.Services.LG AddGenericPictureAction("blackStabilizer", minValue: -30, maxValue: 30, category: "other", title: "Black Stabilizer", fromModelYear: ModelYear.Series2021); AddGenericPictureAction("whiteStabilizer", minValue: -30, maxValue: 30, category: "other", title: "White Stabilizer", fromModelYear: ModelYear.Series2021); AddGenericPictureAction("blueLight", typeof(BlueLight), category: "other", title: "Reduce Blue Light", fromModelYear: ModelYear.Series2021); + AddGenericPictureAction("noiseReduction", typeof(OffToHigh), title: "Noise Reduction"); + AddGenericPictureAction("mpegNoiseReduction", typeof(OffToHigh), title: "MPEG Noise Reduction"); AddHdmiPictureAction("gameMode_hdmi", typeof(OffToOn), category: "other", title: "Game Optimizer HDMI1", fromModelYear: ModelYear.Series2021); AddGenericPictureAction("gameOptimization", typeof(OffToOn), category: "other", title: "VRR & G-Sync", fromModelYear: ModelYear.Series2021); @@ -262,6 +265,7 @@ namespace ColorControl.Services.LG AddSetDeviceConfigAction("HDMI_3_icon", typeof(HdmiIcon), "HDMI 3 icon"); AddSetDeviceConfigAction("HDMI_4_icon", typeof(HdmiIcon), "HDMI 4 icon"); + AddVolumeAction("audioVolume", "Volume"); AddGenericPictureAction("soundMode", typeof(SoundMode), category: "sound", title: "Sound Mode"); AddGenericPictureAction("smartSoundMode", typeof(OffToOn), category: "sound", title: "Adaptive Sound Control"); AddGenericPictureAction("soundOutput", typeof(SoundOutput), category: "sound", title: "Sound Output"); @@ -378,6 +382,22 @@ namespace ColorControl.Services.LG _invokableActions.Add(action); } + private void AddVolumeAction(string name, string title, ModelYear fromModelYear = ModelYear.None) + { + var action = new InvokableAction + { + Name = name, + AsyncFunction = GenericVolumeAction, + MinValue = 0, + MaxValue = 100, + Title = title == null ? Utils.FirstCharUpperCase(name) : title, + Category = "sound", + FromModelYear = fromModelYear + }; + + _invokableActions.Add(action); + } + public void AddGameBarAction(string name) { if (!ActionsOnGameBar.Contains(name)) @@ -424,7 +444,7 @@ namespace ColorControl.Services.LG SetModelYear(); } - //await _lgTvApi.SubscribeVolume(VolumeChanged); + await _lgTvApi.SubscribeVolume(VolumeChanged); await _lgTvApi.SubscribePowerState(PowerStateChanged); await _lgTvApi.SubscribePictureSettings(PictureSettingsChanged); await _lgTvApi.SubscribeForegroundApp(ForegroundAppChanged); @@ -493,6 +513,20 @@ namespace ColorControl.Services.LG public bool VolumeChanged(dynamic payload) { + if (payload.volume != null) + { + PictureSettings.Volume = Utils.ParseDynamicAsInt(payload.volume, PictureSettings.Volume); + } + + var volumeAction = _invokableActions.FirstOrDefault(a => a.Name == "audioVolume"); + + if (volumeAction != null) + { + volumeAction.CurrentValue = PictureSettings.Volume; + } + + PictureSettingsChangedEvent?.Invoke(this, EventArgs.Empty); + return true; } @@ -985,7 +1019,11 @@ namespace ColorControl.Services.LG public List GetInvokableActionsForGameBar() { var actions = GetInvokableActions(); - return actions.Where(a => a.Category == "picture" && (a.EnumType != null && a.EnumType != typeof(PictureMode) || a.MinValue >= 0 && a.MaxValue > 0)).ToList(); + return actions.Where(a => + a.Category == "picture" && (a.EnumType != null && a.EnumType != typeof(PictureMode) || a.MinValue >= 0 && a.MaxValue > 0) || + a.Name == "audioVolume" + ) + .ToList(); } public List GetActionsForGameBar() @@ -1176,6 +1214,25 @@ namespace ColorControl.Services.LG return true; } + private async Task GenericVolumeAction(Dictionary parameters) + { + await CheckConnectionAsync(); + + var values = parameters["value"] as object[]; + var value = values[0]; + + var volume = Utils.ParseInt(value.ToString(), 0); + + await _lgTvApi.SetVolume(volume); + + return true; + } + + public Task SetVolume(int value) + { + return _lgTvApi.SetVolume(value); + } + private void UpdateCurrentValueOfAction(string settingName, string value) { if (settingName == "backlight" || settingName == "contrast" || settingName == "brightness" || settingName == "color") diff --git a/ColorControl/Services/LG/LgGameBar.Designer.cs b/ColorControl/Services/LG/LgGameBar.Designer.cs index be7188d..11b4ca8 100644 --- a/ColorControl/Services/LG/LgGameBar.Designer.cs +++ b/ColorControl/Services/LG/LgGameBar.Designer.cs @@ -29,103 +29,104 @@ namespace ColorControl.Services.LG /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.flowPanel = new System.Windows.Forms.FlowLayoutPanel(); - this.btnClose = new System.Windows.Forms.Button(); - this.lblTvName = new System.Windows.Forms.Label(); - this.tmrHide = new System.Windows.Forms.Timer(this.components); - this.lblProcessName = new System.Windows.Forms.Label(); - this.SuspendLayout(); + components = new System.ComponentModel.Container(); + flowPanel = new System.Windows.Forms.FlowLayoutPanel(); + btnClose = new System.Windows.Forms.Button(); + lblTvName = new System.Windows.Forms.Label(); + tmrHide = new System.Windows.Forms.Timer(components); + lblProcessName = new System.Windows.Forms.Label(); + SuspendLayout(); // // flowPanel // - this.flowPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.flowPanel.Location = new System.Drawing.Point(14, 47); - this.flowPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.flowPanel.Name = "flowPanel"; - this.flowPanel.Size = new System.Drawing.Size(270, 325); - this.flowPanel.TabIndex = 0; - this.flowPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RemoteControlForm_MouseDown); - this.flowPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.flowPanel_MouseMove); - this.flowPanel.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.flowPanel_PreviewKeyDown); + flowPanel.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + flowPanel.Location = new System.Drawing.Point(14, 47); + flowPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + flowPanel.Name = "flowPanel"; + flowPanel.Size = new System.Drawing.Size(270, 325); + flowPanel.TabIndex = 0; + flowPanel.MouseDown += RemoteControlForm_MouseDown; + flowPanel.MouseEnter += flowPanel_MouseEnter; + flowPanel.MouseMove += flowPanel_MouseMove; + flowPanel.PreviewKeyDown += flowPanel_PreviewKeyDown; // // btnClose // - this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnClose.FlatAppearance.BorderColor = System.Drawing.Color.DarkGray; - this.btnClose.FlatAppearance.BorderSize = 0; - this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnClose.ForeColor = System.Drawing.Color.White; - this.btnClose.Location = new System.Drawing.Point(280, 0); - this.btnClose.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.btnClose.Name = "btnClose"; - this.btnClose.Size = new System.Drawing.Size(16, 27); - this.btnClose.TabIndex = 1; - this.btnClose.TabStop = false; - this.btnClose.Text = "x"; - this.btnClose.UseVisualStyleBackColor = true; - this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + btnClose.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; + btnClose.FlatAppearance.BorderColor = System.Drawing.Color.DarkGray; + btnClose.FlatAppearance.BorderSize = 0; + btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + btnClose.ForeColor = System.Drawing.Color.White; + btnClose.Location = new System.Drawing.Point(280, 0); + btnClose.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnClose.Name = "btnClose"; + btnClose.Size = new System.Drawing.Size(16, 27); + btnClose.TabIndex = 1; + btnClose.TabStop = false; + btnClose.Text = "x"; + btnClose.UseVisualStyleBackColor = true; + btnClose.Click += btnClose_Click; // // lblTvName // - this.lblTvName.AutoSize = true; - this.lblTvName.ForeColor = System.Drawing.Color.White; - this.lblTvName.Location = new System.Drawing.Point(14, 0); - this.lblTvName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lblTvName.Name = "lblTvName"; - this.lblTvName.Size = new System.Drawing.Size(25, 15); - this.lblTvName.TabIndex = 0; - this.lblTvName.Text = " "; + lblTvName.AutoSize = true; + lblTvName.ForeColor = System.Drawing.Color.White; + lblTvName.Location = new System.Drawing.Point(14, 0); + lblTvName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblTvName.Name = "lblTvName"; + lblTvName.Size = new System.Drawing.Size(25, 15); + lblTvName.TabIndex = 0; + lblTvName.Text = " "; // // tmrHide // - this.tmrHide.Interval = 5000; - this.tmrHide.Tick += new System.EventHandler(this.tmrHide_Tick); + tmrHide.Interval = 5000; + tmrHide.Tick += tmrHide_Tick; // // lblProcessName // - this.lblProcessName.AutoSize = true; - this.lblProcessName.ForeColor = System.Drawing.Color.White; - this.lblProcessName.Location = new System.Drawing.Point(14, 23); - this.lblProcessName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lblProcessName.Name = "lblProcessName"; - this.lblProcessName.Size = new System.Drawing.Size(25, 15); - this.lblProcessName.TabIndex = 2; - this.lblProcessName.Text = " "; + lblProcessName.AutoSize = true; + lblProcessName.ForeColor = System.Drawing.Color.White; + lblProcessName.Location = new System.Drawing.Point(14, 23); + lblProcessName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblProcessName.Name = "lblProcessName"; + lblProcessName.Size = new System.Drawing.Size(25, 15); + lblProcessName.TabIndex = 2; + lblProcessName.Text = " "; // // LgGameBar // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.Color.Black; - this.ClientSize = new System.Drawing.Size(298, 387); - this.Controls.Add(this.lblProcessName); - this.Controls.Add(this.lblTvName); - this.Controls.Add(this.btnClose); - this.Controls.Add(this.flowPanel); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.KeyPreview = true; - this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "LgGameBar"; - this.Opacity = 0.7D; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; - this.Text = "RemoteControlForm"; - this.TopMost = true; - this.Activated += new System.EventHandler(this.LgGameBar_Activated); - this.Deactivate += new System.EventHandler(this.LgGameBar_Deactivate); - this.Load += new System.EventHandler(this.RemoteControlForm_Load); - this.Shown += new System.EventHandler(this.RemoteControlForm_Shown); - this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.RemoteControlForm_KeyDown); - this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RemoteControlForm_KeyUp); - this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RemoteControlForm_MouseDown); - this.Move += new System.EventHandler(this.LgGameBar_Move); - this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.RemoteControlForm_PreviewKeyDown); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + BackColor = System.Drawing.Color.Black; + ClientSize = new System.Drawing.Size(298, 387); + Controls.Add(lblProcessName); + Controls.Add(lblTvName); + Controls.Add(btnClose); + Controls.Add(flowPanel); + FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + KeyPreview = true; + Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + MaximizeBox = false; + MinimizeBox = false; + Name = "LgGameBar"; + Opacity = 0.7D; + StartPosition = System.Windows.Forms.FormStartPosition.Manual; + Text = "RemoteControlForm"; + TopMost = true; + Activated += LgGameBar_Activated; + Deactivate += LgGameBar_Deactivate; + Load += RemoteControlForm_Load; + Shown += RemoteControlForm_Shown; + KeyDown += RemoteControlForm_KeyDown; + KeyUp += RemoteControlForm_KeyUp; + MouseDown += RemoteControlForm_MouseDown; + MouseEnter += LgGameBar_MouseEnter; + MouseLeave += LgGameBar_MouseLeave; + Move += LgGameBar_Move; + PreviewKeyDown += RemoteControlForm_PreviewKeyDown; + ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/ColorControl/Services/LG/LgGameBar.cs b/ColorControl/Services/LG/LgGameBar.cs index d8b2420..c877f34 100644 --- a/ColorControl/Services/LG/LgGameBar.cs +++ b/ColorControl/Services/LG/LgGameBar.cs @@ -23,6 +23,7 @@ namespace ColorControl.Services.LG private LgDevice _lgDevice; private ToolTip _toolTip; private bool _settingChanged = false; + private bool _mouseHovering = false; private List _trackBars = new List(); private List _lastActions = new List(); @@ -279,6 +280,12 @@ namespace ColorControl.Services.LG { _lgService.Config.GameBarLeft = Left; _lgService.Config.GameBarTop = Top; + + if (_mouseHovering) + { + return; + } + Hide(); } @@ -301,7 +308,18 @@ namespace ColorControl.Services.LG value = enumValue.ToString(); } - await _lgDevice.SetSystemSettings(setting.Name, value); + try + { + if (setting.Name == "audioVolume") + { + await _lgDevice.SetVolume(Utils.ParseInt(value)); + } + else + { + await _lgDevice.SetSystemSettings(setting.Name, value); + } + } + catch (Exception) { } if (_toolTip != null) { @@ -324,7 +342,23 @@ namespace ColorControl.Services.LG private void ResetAutoHide() { tmrHide.Enabled = false; + tmrHide.Interval = _lgService.Config.GameBarShowingTime; tmrHide.Enabled = true; } + + private void LgGameBar_MouseEnter(object sender, EventArgs e) + { + _mouseHovering = true; + } + + private void LgGameBar_MouseLeave(object sender, EventArgs e) + { + _mouseHovering = false; + } + + private void flowPanel_MouseEnter(object sender, EventArgs e) + { + _mouseHovering = true; + } } } diff --git a/ColorControl/Services/LG/LgGameBar.resx b/ColorControl/Services/LG/LgGameBar.resx index 7dbbdc6..653b7a3 100644 --- a/ColorControl/Services/LG/LgGameBar.resx +++ b/ColorControl/Services/LG/LgGameBar.resx @@ -1,4 +1,64 @@ - + + + diff --git a/ColorControl/Services/LG/LgPanel.cs b/ColorControl/Services/LG/LgPanel.cs index 77b9c5c..51125c2 100644 --- a/ColorControl/Services/LG/LgPanel.cs +++ b/ColorControl/Services/LG/LgPanel.cs @@ -1173,59 +1173,76 @@ Do you want to continue?"; { var advancedWasEnabled = _lgService.Config.ShowAdvancedActions; + var retriesField = new FieldDefinition + { + FieldType = FieldType.Numeric, + Label = "Maximum number of retries powering on after startup/resume.", + SubLabel = "Retries are necessary to wait for the network link of your pc to be established.", + MinValue = 1, + MaxValue = 40, + Value = _lgService.Config.PowerOnRetries + }; + + var restartDelayField = new FieldDefinition + { + FieldType = FieldType.Numeric, + Label = "Delay when shutting down/restarting PC (milliseconds).", + SubLabel = "This delay may prevent the tv from powering off when restarting the pc.", + MinValue = 0, + MaxValue = 5000, + Value = _lgService.Config.ShutdownDelay + }; + + var quickAccessField = new FieldDefinition + { + FieldType = FieldType.Shortcut, + Label = "Quick Access shortcut", + Value = _lgService.Config.QuickAccessShortcut + }; + + var gameBarShortcutField = new FieldDefinition + { + FieldType = FieldType.Shortcut, + Label = "Game Bar shortcut", + Value = _lgService.Config.GameBarShortcut + }; + + var gameBarTimeoutField = new FieldDefinition + { + FieldType = FieldType.Numeric, + Label = "Game Bar showing time (milliseconds)", + MinValue = 1000, + MaxValue = 60000, + Value = _lgService.Config.GameBarShowingTime + }; + + var advancedField = new FieldDefinition + { + FieldType = FieldType.CheckBox, + Label = "Show advanced actions under the Expert-button (InStart, EzAdjust, Software Update)", + Value = _lgService.Config.ShowAdvancedActions + }; + + var setSelectedDeviceField = new FieldDefinition + { + FieldType = FieldType.CheckBox, + Label = "Automatically set selected device to last powered on", + Value = _lgService.Config.SetSelectedDeviceByPowerOn + }; + + var buttonDelayField = new FieldDefinition + { + FieldType = FieldType.Numeric, + Label = "Default delay between remote control button presses (milliseconds).", + SubLabel = "Increasing this delay may prevent skipped button presses.", + MinValue = 100, + MaxValue = 2000, + Value = _lgService.Config.DefaultButtonDelay + }; + var fields = new FieldDefinition[] { - new() - { - FieldType = FieldType.Numeric, - Label = "Maximum number of retries powering on after startup/resume.", - SubLabel = "Retries are necessary to wait for the network link of your pc to be established.", - MinValue = 1, - MaxValue = 40, - Value = _lgService.Config.PowerOnRetries - }, - new() - { - FieldType = FieldType.Numeric, - Label = "Delay when shutting down/restarting PC (milliseconds).", - SubLabel = "This delay may prevent the tv from powering off when restarting the pc.", - MinValue = 0, - MaxValue = 5000, - Value = _lgService.Config.ShutdownDelay - }, - new() - { - FieldType = FieldType.Shortcut, - Label = "Quick Access shortcut", - Value = _lgService.Config.QuickAccessShortcut - }, - new() - { - FieldType = FieldType.Shortcut, - Label = "Game Bar shortcut", - Value = _lgService.Config.GameBarShortcut - }, - new() - { - FieldType = FieldType.CheckBox, - Label = "Show advanced actions under the Expert-button (InStart, EzAdjust, Software Update)", - Value = _lgService.Config.ShowAdvancedActions - }, - new() - { - FieldType = FieldType.CheckBox, - Label = "Automatically set selected device to last powered on", - Value = _lgService.Config.SetSelectedDeviceByPowerOn - }, - new() - { - FieldType = FieldType.Numeric, - Label = "Default delay between remote control button presses (milliseconds).", - SubLabel = "Increasing this delay may prevent skipped button presses.", - MinValue = 100, - MaxValue = 2000, - Value = _lgService.Config.DefaultButtonDelay - } + retriesField, restartDelayField, quickAccessField, gameBarShortcutField, gameBarTimeoutField, advancedField, setSelectedDeviceField, buttonDelayField }; var values = MessageForms.ShowDialog("LG controller settings", fields); @@ -1235,17 +1252,18 @@ Do you want to continue?"; return; } - _lgService.Config.PowerOnRetries = values[0].ValueAsInt; - _lgService.Config.ShutdownDelay = values[1].ValueAsInt; + _lgService.Config.PowerOnRetries = retriesField.ValueAsInt; + _lgService.Config.ShutdownDelay = restartDelayField.ValueAsInt; - var shortcutQA = values[2].Value.ToString(); + var shortcutQA = quickAccessField.Value.ToString(); _lgService.Config.QuickAccessShortcut = shortcutQA; KeyboardShortcutManager.RegisterShortcut(SHORTCUTID_LGQA, _lgService.Config.QuickAccessShortcut); - var shortcutGB = values[3].Value.ToString(); + var shortcutGB = gameBarShortcutField.Value.ToString(); _lgService.Config.GameBarShortcut = shortcutGB; + _lgService.Config.GameBarShowingTime = gameBarTimeoutField.ValueAsInt; if (string.IsNullOrEmpty(shortcutGB)) { @@ -1256,9 +1274,9 @@ Do you want to continue?"; KeyboardShortcutManager.RegisterShortcut(SHORTCUTID_GAMEBAR, shortcutGB); } - _lgService.Config.ShowAdvancedActions = values[4].ValueAsBool; - _lgService.Config.SetSelectedDeviceByPowerOn = values[5].ValueAsBool; - _lgService.Config.DefaultButtonDelay = values[6].ValueAsInt; + _lgService.Config.ShowAdvancedActions = advancedField.ValueAsBool; + _lgService.Config.SetSelectedDeviceByPowerOn = setSelectedDeviceField.ValueAsBool; + _lgService.Config.DefaultButtonDelay = buttonDelayField.ValueAsInt; if (!advancedWasEnabled && _lgService.Config.ShowAdvancedActions) { diff --git a/ColorControl/Services/LG/LgServiceConfig.cs b/ColorControl/Services/LG/LgServiceConfig.cs index 1e76da1..57657d0 100644 --- a/ColorControl/Services/LG/LgServiceConfig.cs +++ b/ColorControl/Services/LG/LgServiceConfig.cs @@ -19,6 +19,7 @@ namespace ColorControl.Services.LG public bool SetSelectedDeviceByPowerOn { get; set; } public string QuickAccessShortcut { get; set; } public int DefaultButtonDelay { get; set; } + public int GameBarShowingTime { get; set; } public LgServiceConfig() { @@ -30,6 +31,7 @@ namespace ColorControl.Services.LG GameBarTop = 100; GameBarLeft = 100; DefaultButtonDelay = 200; + GameBarShowingTime = 5000; } } } diff --git a/ColorControl/Services/NVIDIA/NvDitherPanel.Designer.cs b/ColorControl/Services/NVIDIA/NvDitherPanel.Designer.cs index 2aafc39..969e3ad 100644 --- a/ColorControl/Services/NVIDIA/NvDitherPanel.Designer.cs +++ b/ColorControl/Services/NVIDIA/NvDitherPanel.Designer.cs @@ -28,145 +28,179 @@ /// private void InitializeComponent() { - this.grpNvidiaOptions = new System.Windows.Forms.GroupBox(); - this.lblDitheringDisplay = new System.Windows.Forms.Label(); - this.cbxDitheringDisplay = new System.Windows.Forms.ComboBox(); - this.lblDitheringMode = new System.Windows.Forms.Label(); - this.cbxDitheringMode = new System.Windows.Forms.ComboBox(); - this.lblDitheringBitDepth = new System.Windows.Forms.Label(); - this.cbxDitheringBitDepth = new System.Windows.Forms.ComboBox(); - this.chkDitheringEnabled = new System.Windows.Forms.CheckBox(); - this.pbGradient = new System.Windows.Forms.PictureBox(); - this.grpNvidiaOptions.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pbGradient)).BeginInit(); - this.SuspendLayout(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NvDitherPanel)); + grpNvidiaOptions = new System.Windows.Forms.GroupBox(); + btnSetRegistryKey = new System.Windows.Forms.Button(); + btnRestartDriver = new System.Windows.Forms.Button(); + lblDitherRegistry = new System.Windows.Forms.Label(); + lblDitheringDisplay = new System.Windows.Forms.Label(); + cbxDitheringDisplay = new System.Windows.Forms.ComboBox(); + lblDitheringMode = new System.Windows.Forms.Label(); + cbxDitheringMode = new System.Windows.Forms.ComboBox(); + lblDitheringBitDepth = new System.Windows.Forms.Label(); + cbxDitheringBitDepth = new System.Windows.Forms.ComboBox(); + chkDitheringEnabled = new System.Windows.Forms.CheckBox(); + pbGradient = new System.Windows.Forms.PictureBox(); + grpNvidiaOptions.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pbGradient).BeginInit(); + SuspendLayout(); // // grpNvidiaOptions // - this.grpNvidiaOptions.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.grpNvidiaOptions.Controls.Add(this.lblDitheringDisplay); - this.grpNvidiaOptions.Controls.Add(this.cbxDitheringDisplay); - this.grpNvidiaOptions.Controls.Add(this.lblDitheringMode); - this.grpNvidiaOptions.Controls.Add(this.cbxDitheringMode); - this.grpNvidiaOptions.Controls.Add(this.lblDitheringBitDepth); - this.grpNvidiaOptions.Controls.Add(this.cbxDitheringBitDepth); - this.grpNvidiaOptions.Controls.Add(this.chkDitheringEnabled); - this.grpNvidiaOptions.Controls.Add(this.pbGradient); - this.grpNvidiaOptions.Location = new System.Drawing.Point(4, 3); - this.grpNvidiaOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.grpNvidiaOptions.Name = "grpNvidiaOptions"; - this.grpNvidiaOptions.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.grpNvidiaOptions.Size = new System.Drawing.Size(856, 479); - this.grpNvidiaOptions.TabIndex = 6; - this.grpNvidiaOptions.TabStop = false; - this.grpNvidiaOptions.Text = "NVIDIA options - test dithering"; + grpNvidiaOptions.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + grpNvidiaOptions.Controls.Add(btnSetRegistryKey); + grpNvidiaOptions.Controls.Add(btnRestartDriver); + grpNvidiaOptions.Controls.Add(lblDitherRegistry); + grpNvidiaOptions.Controls.Add(lblDitheringDisplay); + grpNvidiaOptions.Controls.Add(cbxDitheringDisplay); + grpNvidiaOptions.Controls.Add(lblDitheringMode); + grpNvidiaOptions.Controls.Add(cbxDitheringMode); + grpNvidiaOptions.Controls.Add(lblDitheringBitDepth); + grpNvidiaOptions.Controls.Add(cbxDitheringBitDepth); + grpNvidiaOptions.Controls.Add(chkDitheringEnabled); + grpNvidiaOptions.Controls.Add(pbGradient); + grpNvidiaOptions.Location = new System.Drawing.Point(4, 3); + grpNvidiaOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpNvidiaOptions.MinimumSize = new System.Drawing.Size(300, 100); + grpNvidiaOptions.Name = "grpNvidiaOptions"; + grpNvidiaOptions.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + grpNvidiaOptions.Size = new System.Drawing.Size(856, 479); + grpNvidiaOptions.TabIndex = 6; + grpNvidiaOptions.TabStop = false; + grpNvidiaOptions.Text = "NVIDIA options - test dithering"; + // + // btnSetRegistryKey + // + btnSetRegistryKey.Location = new System.Drawing.Point(381, 17); + btnSetRegistryKey.Name = "btnSetRegistryKey"; + btnSetRegistryKey.Size = new System.Drawing.Size(150, 23); + btnSetRegistryKey.TabIndex = 13; + btnSetRegistryKey.Text = "Set dither registry key"; + btnSetRegistryKey.UseVisualStyleBackColor = true; + btnSetRegistryKey.Click += btnSetRegistryKey_Click; + // + // btnRestartDriver + // + btnRestartDriver.Location = new System.Drawing.Point(539, 16); + btnRestartDriver.Name = "btnRestartDriver"; + btnRestartDriver.Size = new System.Drawing.Size(150, 23); + btnRestartDriver.TabIndex = 12; + btnRestartDriver.Text = "Restart driver"; + btnRestartDriver.UseVisualStyleBackColor = true; + btnRestartDriver.Click += btnRestartDriver_Click; + // + // lblDitherRegistry + // + lblDitherRegistry.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + lblDitherRegistry.Location = new System.Drawing.Point(381, 47); + lblDitherRegistry.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblDitherRegistry.Name = "lblDitherRegistry"; + lblDitherRegistry.Size = new System.Drawing.Size(467, 78); + lblDitherRegistry.TabIndex = 11; + lblDitherRegistry.Text = resources.GetString("lblDitherRegistry.Text"); // // lblDitheringDisplay // - this.lblDitheringDisplay.AutoSize = true; - this.lblDitheringDisplay.Location = new System.Drawing.Point(8, 23); - this.lblDitheringDisplay.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lblDitheringDisplay.Name = "lblDitheringDisplay"; - this.lblDitheringDisplay.Size = new System.Drawing.Size(48, 15); - this.lblDitheringDisplay.TabIndex = 9; - this.lblDitheringDisplay.Text = "Display:"; + lblDitheringDisplay.AutoSize = true; + lblDitheringDisplay.Location = new System.Drawing.Point(8, 23); + lblDitheringDisplay.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblDitheringDisplay.Name = "lblDitheringDisplay"; + lblDitheringDisplay.Size = new System.Drawing.Size(48, 15); + lblDitheringDisplay.TabIndex = 9; + lblDitheringDisplay.Text = "Display:"; // // cbxDitheringDisplay // - this.cbxDitheringDisplay.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbxDitheringDisplay.FormattingEnabled = true; - this.cbxDitheringDisplay.Location = new System.Drawing.Point(75, 17); - this.cbxDitheringDisplay.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.cbxDitheringDisplay.Name = "cbxDitheringDisplay"; - this.cbxDitheringDisplay.Size = new System.Drawing.Size(212, 23); - this.cbxDitheringDisplay.TabIndex = 8; - this.cbxDitheringDisplay.SelectedIndexChanged += new System.EventHandler(this.cbxDitheringDisplay_SelectedIndexChanged); + cbxDitheringDisplay.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + cbxDitheringDisplay.DropDownWidth = 300; + cbxDitheringDisplay.FormattingEnabled = true; + cbxDitheringDisplay.Location = new System.Drawing.Point(75, 17); + cbxDitheringDisplay.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + cbxDitheringDisplay.Name = "cbxDitheringDisplay"; + cbxDitheringDisplay.Size = new System.Drawing.Size(298, 23); + cbxDitheringDisplay.TabIndex = 8; + cbxDitheringDisplay.SelectedIndexChanged += cbxDitheringDisplay_SelectedIndexChanged; // // lblDitheringMode // - this.lblDitheringMode.AutoSize = true; - this.lblDitheringMode.Location = new System.Drawing.Point(8, 105); - this.lblDitheringMode.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lblDitheringMode.Name = "lblDitheringMode"; - this.lblDitheringMode.Size = new System.Drawing.Size(41, 15); - this.lblDitheringMode.TabIndex = 7; - this.lblDitheringMode.Text = "Mode:"; + lblDitheringMode.AutoSize = true; + lblDitheringMode.Location = new System.Drawing.Point(8, 105); + lblDitheringMode.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblDitheringMode.Name = "lblDitheringMode"; + lblDitheringMode.Size = new System.Drawing.Size(41, 15); + lblDitheringMode.TabIndex = 7; + lblDitheringMode.Text = "Mode:"; // // cbxDitheringMode // - this.cbxDitheringMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbxDitheringMode.FormattingEnabled = true; - this.cbxDitheringMode.Location = new System.Drawing.Point(75, 99); - this.cbxDitheringMode.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.cbxDitheringMode.Name = "cbxDitheringMode"; - this.cbxDitheringMode.Size = new System.Drawing.Size(136, 23); - this.cbxDitheringMode.TabIndex = 6; - this.cbxDitheringMode.SelectedIndexChanged += new System.EventHandler(this.cbxDitheringMode_SelectedIndexChanged); + cbxDitheringMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + cbxDitheringMode.FormattingEnabled = true; + cbxDitheringMode.Location = new System.Drawing.Point(75, 99); + cbxDitheringMode.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + cbxDitheringMode.Name = "cbxDitheringMode"; + cbxDitheringMode.Size = new System.Drawing.Size(136, 23); + cbxDitheringMode.TabIndex = 6; + cbxDitheringMode.SelectedIndexChanged += cbxDitheringMode_SelectedIndexChanged; // // lblDitheringBitDepth // - this.lblDitheringBitDepth.AutoSize = true; - this.lblDitheringBitDepth.Location = new System.Drawing.Point(8, 74); - this.lblDitheringBitDepth.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lblDitheringBitDepth.Name = "lblDitheringBitDepth"; - this.lblDitheringBitDepth.Size = new System.Drawing.Size(60, 15); - this.lblDitheringBitDepth.TabIndex = 5; - this.lblDitheringBitDepth.Text = "Bit-depth:"; + lblDitheringBitDepth.AutoSize = true; + lblDitheringBitDepth.Location = new System.Drawing.Point(8, 74); + lblDitheringBitDepth.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblDitheringBitDepth.Name = "lblDitheringBitDepth"; + lblDitheringBitDepth.Size = new System.Drawing.Size(60, 15); + lblDitheringBitDepth.TabIndex = 5; + lblDitheringBitDepth.Text = "Bit-depth:"; // // cbxDitheringBitDepth // - this.cbxDitheringBitDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbxDitheringBitDepth.FormattingEnabled = true; - this.cbxDitheringBitDepth.Location = new System.Drawing.Point(75, 68); - this.cbxDitheringBitDepth.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.cbxDitheringBitDepth.Name = "cbxDitheringBitDepth"; - this.cbxDitheringBitDepth.Size = new System.Drawing.Size(136, 23); - this.cbxDitheringBitDepth.TabIndex = 4; - this.cbxDitheringBitDepth.SelectedIndexChanged += new System.EventHandler(this.cbxDitheringBitDepth_SelectedIndexChanged); + cbxDitheringBitDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + cbxDitheringBitDepth.FormattingEnabled = true; + cbxDitheringBitDepth.Location = new System.Drawing.Point(75, 68); + cbxDitheringBitDepth.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + cbxDitheringBitDepth.Name = "cbxDitheringBitDepth"; + cbxDitheringBitDepth.Size = new System.Drawing.Size(136, 23); + cbxDitheringBitDepth.TabIndex = 4; + cbxDitheringBitDepth.SelectedIndexChanged += cbxDitheringBitDepth_SelectedIndexChanged; // // chkDitheringEnabled // - this.chkDitheringEnabled.AutoSize = true; - this.chkDitheringEnabled.Checked = true; - this.chkDitheringEnabled.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkDitheringEnabled.Location = new System.Drawing.Point(8, 46); - this.chkDitheringEnabled.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.chkDitheringEnabled.Name = "chkDitheringEnabled"; - this.chkDitheringEnabled.Size = new System.Drawing.Size(120, 19); - this.chkDitheringEnabled.TabIndex = 3; - this.chkDitheringEnabled.Text = "Dithering enabled"; - this.chkDitheringEnabled.ThreeState = true; - this.chkDitheringEnabled.UseVisualStyleBackColor = true; - this.chkDitheringEnabled.CheckStateChanged += new System.EventHandler(this.chkDitheringEnabled_CheckStateChanged); + chkDitheringEnabled.AutoSize = true; + chkDitheringEnabled.Checked = true; + chkDitheringEnabled.CheckState = System.Windows.Forms.CheckState.Checked; + chkDitheringEnabled.Location = new System.Drawing.Point(8, 46); + chkDitheringEnabled.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chkDitheringEnabled.Name = "chkDitheringEnabled"; + chkDitheringEnabled.Size = new System.Drawing.Size(120, 19); + chkDitheringEnabled.TabIndex = 3; + chkDitheringEnabled.Text = "Dithering enabled"; + chkDitheringEnabled.ThreeState = true; + chkDitheringEnabled.UseVisualStyleBackColor = true; + chkDitheringEnabled.CheckStateChanged += chkDitheringEnabled_CheckStateChanged; // // pbGradient // - this.pbGradient.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pbGradient.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pbGradient.Location = new System.Drawing.Point(8, 128); - this.pbGradient.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.pbGradient.Name = "pbGradient"; - this.pbGradient.Size = new System.Drawing.Size(840, 345); - this.pbGradient.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.pbGradient.TabIndex = 0; - this.pbGradient.TabStop = false; + pbGradient.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + pbGradient.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + pbGradient.Location = new System.Drawing.Point(8, 128); + pbGradient.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + pbGradient.Name = "pbGradient"; + pbGradient.Size = new System.Drawing.Size(840, 345); + pbGradient.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + pbGradient.TabIndex = 0; + pbGradient.TabStop = false; // // NvDitherPanel // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.grpNvidiaOptions); - this.Name = "NvDitherPanel"; - this.Size = new System.Drawing.Size(864, 485); - this.grpNvidiaOptions.ResumeLayout(false); - this.grpNvidiaOptions.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pbGradient)).EndInit(); - this.ResumeLayout(false); - + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + Controls.Add(grpNvidiaOptions); + Name = "NvDitherPanel"; + Size = new System.Drawing.Size(864, 485); + grpNvidiaOptions.ResumeLayout(false); + grpNvidiaOptions.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pbGradient).EndInit(); + ResumeLayout(false); } #endregion @@ -180,5 +214,8 @@ private System.Windows.Forms.CheckBox chkDitheringEnabled; private System.Windows.Forms.Label lblDitheringDisplay; private System.Windows.Forms.ComboBox cbxDitheringDisplay; + private System.Windows.Forms.Label lblDitherRegistry; + private System.Windows.Forms.Button btnRestartDriver; + private System.Windows.Forms.Button btnSetRegistryKey; } } diff --git a/ColorControl/Services/NVIDIA/NvDitherPanel.cs b/ColorControl/Services/NVIDIA/NvDitherPanel.cs index cf6747e..68f17a9 100644 --- a/ColorControl/Services/NVIDIA/NvDitherPanel.cs +++ b/ColorControl/Services/NVIDIA/NvDitherPanel.cs @@ -93,11 +93,11 @@ namespace ColorControl.Services.NVIDIA } } - private void ApplyDitheringOptions() + private bool ApplyDitheringOptions(bool setRegistry = false, bool restartDriver = false) { if (_updatingDitherSettings) { - return; + return false; } var state = chkDitheringEnabled.CheckState switch { CheckState.Checked => NvDitherState.Enabled, CheckState.Unchecked => NvDitherState.Disabled, _ => NvDitherState.Auto }; @@ -105,10 +105,14 @@ namespace ColorControl.Services.NVIDIA var mode = cbxDitheringMode.SelectedIndex; var display = ((NvDisplayInfo)cbxDitheringDisplay.SelectedItem)?.Display; - if (_nvService.SetDithering(state, (uint)bitDepth, (uint)(mode > -1 ? mode : (int)NvDitherMode.Temporal), currentDisplay: display) && state == NvDitherState.Auto) + var result = _nvService.SetDithering(state, (uint)bitDepth, (uint)(mode > -1 ? mode : (int)NvDitherMode.Temporal), currentDisplay: display, setRegistryKey: setRegistry, restartDriver: restartDriver); + + if (result && state == NvDitherState.Auto) { UpdateDitherSettings(); } + + return result; } private void cbxDitheringBitDepth_SelectedIndexChanged(object sender, EventArgs e) @@ -144,5 +148,22 @@ namespace ColorControl.Services.NVIDIA RefreshDisplays(); UpdateDitherSettings(); } + + private void btnRestartDriver_Click(object sender, EventArgs e) + { + _nvService.RestartDriver(); + } + + private void btnSetRegistryKey_Click(object sender, EventArgs e) + { + if (ApplyDitheringOptions(true)) + { + MessageForms.InfoOk("Dither settings successfully written to the registry."); + } + else + { + MessageForms.ErrorOk("There was an error writing the dither settings to the registry. See the log for more details."); + } + } } } diff --git a/ColorControl/Services/NVIDIA/NvDitherPanel.resx b/ColorControl/Services/NVIDIA/NvDitherPanel.resx index f298a7b..c69052b 100644 --- a/ColorControl/Services/NVIDIA/NvDitherPanel.resx +++ b/ColorControl/Services/NVIDIA/NvDitherPanel.resx @@ -1,4 +1,64 @@ - + + + @@ -57,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Setting the dither registry key saves current settings to the registry. Changing the settings should normally do this already, but this provides a way to force it. Setting the registry key and then restarting the driver is workaround for high bandwidth displays (which use DSC) where the normal dither settings have an effect on only half the screen. + \ No newline at end of file diff --git a/ColorControl/Services/NVIDIA/NvPanel.cs b/ColorControl/Services/NVIDIA/NvPanel.cs index 670bf7a..eeaf9aa 100644 --- a/ColorControl/Services/NVIDIA/NvPanel.cs +++ b/ColorControl/Services/NVIDIA/NvPanel.cs @@ -662,7 +662,7 @@ namespace ColorControl.Services.NVIDIA subItemUnchanged.Font = _menuItemFonts[subItemUnchanged.Checked]; } - if (driverSetting.SettingId == NvService.DRS_FRAME_RATE_LIMITER_V3) + if (NvService.RangeDriverSettings.Contains(driverSetting.SettingId)) { var value = settingMeta.DwordValues.FirstOrDefault(v => v.ValueName == driverSetting.ValueText); @@ -670,7 +670,7 @@ namespace ColorControl.Services.NVIDIA var subItem = FormUtils.BuildMenuItem(item.DropDownItems, subItemName, "", onClick: driverSettingFrameRateNvMenuItem_Click); var metaValue = settingMeta.DwordValues.FirstOrDefault(v => v.Value == presetSetting); - subItem.Text = $"{metaValue?.ValueName ?? "??FPS"} (click to change)"; + subItem.Text = $"{metaValue?.ValueName ?? (driverSetting.SettingId == NvService.DRS_FRAME_RATE_LIMITER_V3 ? "??FPS" : "default")} (click to change)"; subItem.Tag = value?.Value ?? 0; subItem.Checked = presetSetting != defaultValue; diff --git a/ColorControl/Services/NVIDIA/NvService.cs b/ColorControl/Services/NVIDIA/NvService.cs index 9fc7759..8b56f7d 100644 --- a/ColorControl/Services/NVIDIA/NvService.cs +++ b/ColorControl/Services/NVIDIA/NvService.cs @@ -7,6 +7,7 @@ using ColorControl.Shared.Forms; using ColorControl.Shared.Native; using ColorControl.Shared.Services; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Win32; using Newtonsoft.Json; using novideo_srgb; using nspector.Common; @@ -29,6 +30,8 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Security.AccessControl; +using System.Security.Principal; using System.Threading; using System.Threading.Tasks; using static ColorControl.Shared.Contracts.NVIDIA.NvHdrSettings; @@ -78,7 +81,7 @@ namespace ColorControl.Services.NVIDIA PreserveSig = true)] private static extern IntPtr NvAPI64_QueryInterface(uint interfaceId); - [FunctionId(FunctionId.NvAPI_Disp_SetDitherControl)] + [FunctionId(FunctionId.NvAPI_GPU_SetDitherControl)] public delegate int NvAPI_Disp_SetDitherControl( [In] PhysicalGPUHandle physicalGpu, [In] uint OutputId, @@ -87,7 +90,7 @@ namespace ColorControl.Services.NVIDIA [In] uint mode ); - [FunctionId(FunctionId.NvAPI_Disp_GetDitherControl)] + [FunctionId(FunctionId.NvAPI_GPU_GetDitherControl)] public delegate int NvAPI_Disp_GetDitherControl( [In] uint DisplayId, [MarshalAs(UnmanagedType.Struct)] ref NV_GPU_DITHER_CONTROL_V1 ditherControl); @@ -115,6 +118,11 @@ namespace ColorControl.Services.NVIDIA ref NV_DISPLAY_OUTPUT_MODE pDisplayMode ); + [FunctionId(FunctionId.NvAPI_RestartDisplayDriver)] + public delegate void NvAPI_RestartDisplayDriver(); + + // NvAPI_RestartDisplayDriver B4B26B65 + //public struct NV_HDR_METADATA_V1 //{ // public uint version; //!< Version of this structure @@ -168,6 +176,12 @@ namespace ColorControl.Services.NVIDIA //public const uint DRS_ULTRA_LOW_LATENCY = 0x10835000; public const uint DRS_PRERENDERED_FRAMES = 8102046; public const uint DRS_FRAME_RATE_LIMITER_V3 = 277041154; + public const uint DRS_RTX_HDR_PEAK_BRIGHTNESS = 0x00DD48FC; + public const uint DRS_RTX_HDR_MIDDLE_GREY = 0x00DD48FD; + public const uint DRS_RTX_HDR_CONTRAST = 0x00DD48FE; + public const uint DRS_RTX_HDR_SATURATION = 0x00DD48FF; + public const uint DRS_RTX_DYNAMIC_VIBRANCE_INTENSITY = 0x00ABAB22; + public const uint DRS_RTX_DYNAMIC_VIBRANCE_SATURATION_BOOST = 0x00ABAB13; public const uint DRS_ANISOTROPIC_FILTERING_SETTING = 0x101E61A9; public const uint DRS_ANISOTROPIC_FILTER_OPTIMIZATION = 0x0084CD70; @@ -179,6 +193,8 @@ namespace ColorControl.Services.NVIDIA public const uint DRS_RBAR_OPTIONS = 0X000F00BB; public const uint DRS_RBAR_SIZE_LIMIT = 0X000F00FF; + public static uint[] RangeDriverSettings = [DRS_FRAME_RATE_LIMITER_V3, DRS_RTX_HDR_PEAK_BRIGHTNESS, DRS_RTX_HDR_MIDDLE_GREY, DRS_RTX_HDR_CONTRAST, DRS_RTX_HDR_SATURATION, DRS_RTX_DYNAMIC_VIBRANCE_INTENSITY, DRS_RTX_DYNAMIC_VIBRANCE_SATURATION_BOOST]; + public uint DriverVersion { get; private set; } public bool OutputModeAvailable => DriverVersion >= 52500; @@ -798,15 +814,88 @@ namespace ColorControl.Services.NVIDIA return resultValue == 0 ? outputMode : null; } - public bool SetDithering(NvDitherState state, uint bits = 1, uint mode = 4, NvPreset preset = null, Display currentDisplay = null) + public bool SetDitherRegistryKey(string displayRegId, uint state, uint bits = 1, uint mode = 4) { - var delegateValue = DelegateFactory.GetDelegate(); - - if (delegateValue == null) + if (!_winApiService.IsAdministrator()) { - return false; + var result = _rpcClientService.Call(nameof(SetDitherRegistryKey), displayRegId, state, bits, mode); + + return result; } + const string DOMAIN_ALIAS_RID_ADMINS = "S-1-5-32-544"; + + var registryPath = "SYSTEM\\CurrentControlSet\\Services\\nvlddmkm\\State\\DisplayDatabase"; + + var displayDbKey = Registry.LocalMachine.OpenSubKey(registryPath); + + var subKeyNames = displayDbKey.GetSubKeyNames().Where(n => n.Contains(displayRegId)).ToList(); + + foreach (var subKeyName in subKeyNames) + { + var keyPath = $"{registryPath}\\{subKeyName}"; + + try + { + var subKey = Registry.LocalMachine.OpenSubKey(keyPath); + + var ditherValueName = subKey.GetValueNames().FirstOrDefault(n => n == "DitherRegistryKey"); + + if (ditherValueName == null) + { + continue; + } + + subKey = Registry.LocalMachine.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions); + + var accessControl = subKey.GetAccessControl(); + + var rules = accessControl.GetAccessRules(true, true, typeof(SecurityIdentifier)); + var accessRules = new RegistryAccessRule[rules.Count]; + rules.CopyTo(accessRules, 0); + + if (!accessRules.Any(r => r.RegistryRights == RegistryRights.FullControl && r.IdentityReference.Value == DOMAIN_ALIAS_RID_ADMINS && r.AccessControlType == AccessControlType.Allow)) + { + var ownerIdentity = accessControl.GetOwner(typeof(SecurityIdentifier)); + + var adminFullControlRule = new RegistryAccessRule(ownerIdentity, RegistryRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); + + accessControl.SetAccessRule(adminFullControlRule); + + subKey.SetAccessControl(accessControl); + } + + subKey = Registry.LocalMachine.OpenSubKey(keyPath, true); + + var value = subKey.GetValue(ditherValueName) as byte[]; + + if (value == null) + { + continue; + } + + value[9] = (byte)state; + value[10] = (byte)bits; + value[11] = (byte)mode; + + // Checksum + value[12] = (byte)value.Take(12).Sum(v => (uint)v); + + subKey.SetValue(ditherValueName, value, RegistryValueKind.Binary); + + break; + } + catch (Exception ex) + { + Logger.Debug($"Cannot get access to registry key: {keyPath} because: {ex.Message}"); + } + } + + return true; + } + + public bool SetDithering(NvDitherState state, uint bits = 1, uint mode = 4, NvPreset preset = null, Display currentDisplay = null, bool setRegistryKey = false, bool restartDriver = false) + { var result = true; var display = currentDisplay ?? GetCurrentDisplay(); @@ -832,16 +921,73 @@ namespace ColorControl.Services.NVIDIA mode = preset.ditheringMode; } - var resultValue = delegateValue(gpuHandle, displayId, (uint)state, bits, mode); - if (resultValue != 0) + if (setRegistryKey) { - Logger.Error($"Could not set dithering because NvAPI_Disp_SetDitherControl returned a non-zero return code: {resultValue}"); - result = false; + var displays = WindowsDisplayAPI.Display.GetDisplays(); + var path = displays.FirstOrDefault(x => x.DisplayName == display.Name)?.DevicePath; + + if (path == null) + { + Logger.Debug($"Cannot find path for display {display.Name}"); + return false; + } + + var parts = path.Split('#'); + + if (parts.Length < 2) + { + Logger.Debug($"Incorrect path for display {display.Name}"); + return false; + } + + var regId = parts[1]; + + result = SetDitherRegistryKey(regId, (uint)state, bits, mode); + + if (restartDriver) + { + RestartDriver(); + } + } + else + { + var delegateValue = DelegateFactory.GetDelegate(); + + if (delegateValue == null) + { + return false; + } + + var resultValue = delegateValue(gpuHandle, displayId, (uint)state, bits, mode); + if (resultValue != 0) + { + Logger.Error($"Could not set dithering because NvAPI_Disp_SetDitherControl returned a non-zero return code: {resultValue}"); + result = false; + } } return result; } + public bool RestartDriver() + { + if (!_winApiService.IsAdministrator()) + { + return _rpcClientService.Call(nameof(RestartDriver)); + } + + var restartDelegate = DelegateFactory.GetDelegate(); + + if (restartDelegate != null) + { + restartDelegate(); + + return true; + } + + return false; + } + public NV_GPU_DITHER_CONTROL_V1 GetDithering(Display currentDisplay = null) { var version = MAKE_NVAPI_VERSION(1); @@ -1136,6 +1282,8 @@ namespace ColorControl.Services.NVIDIA public void TestResolution() { + SetDithering(NvDitherState.Enabled, 1, 4, setRegistryKey: true); + //GetHdrMetaData(); //SetOutputMode(NV_DISPLAY_OUTPUT_MODE.NV_DISPLAY_OUTPUT_MODE_HDR10PLUS_GAMING); diff --git a/ColorControl/Services/Samsung/SamsungButtons.cs b/ColorControl/Services/Samsung/SamsungButtons.cs index 73795f6..a2983d8 100644 --- a/ColorControl/Services/Samsung/SamsungButtons.cs +++ b/ColorControl/Services/Samsung/SamsungButtons.cs @@ -11,6 +11,7 @@ KEY_CHDOWN, KEY_ENTER, KEY_RETURN, + KEY_HOME, KEY_CH_LIST, KEY_MENU, KEY_SOURCE, @@ -44,5 +45,6 @@ KEY_AD, KEY_PMODE, KEY_ASPECT, + KEY_AMBIENT } } diff --git a/ColorControl/XForms/ColorProfileViewModel.cs b/ColorControl/XForms/ColorProfileViewModel.cs index 976ce03..ceae6df 100644 --- a/ColorControl/XForms/ColorProfileViewModel.cs +++ b/ColorControl/XForms/ColorProfileViewModel.cs @@ -104,7 +104,7 @@ internal class ColorProfileViewModel : BaseViewModel public double WhiteLuminance { get; set; } = 1000; [Range(0, 10)] public double SDRMinBrightness { get; set; } = 0; - [Range(11, 1000)] + [Range(11, 10000)] public double SDRMaxBrightness { get; set; } = 100; [Range(-50, 50)] public double SDRBrightnessBoost { get; set; } diff --git a/ColorControl/XForms/ColorProfileWindow.xaml b/ColorControl/XForms/ColorProfileWindow.xaml index 46066d0..bbc454d 100644 --- a/ColorControl/XForms/ColorProfileWindow.xaml +++ b/ColorControl/XForms/ColorProfileWindow.xaml @@ -65,8 +65,8 @@