瀏覽代碼

UI: Defer Settings window hotkey loading

derrod 2 年之前
父節點
當前提交
b44910726d
共有 4 個文件被更改,包括 44 次插入2 次删除
  1. 1 0
      UI/data/locale/en-US.ini
  2. 19 0
      UI/forms/OBSBasicSettings.ui
  3. 23 2
      UI/window-basic-settings.cpp
  4. 1 0
      UI/window-basic-settings.hpp

+ 1 - 0
UI/data/locale/en-US.ini

@@ -1209,6 +1209,7 @@ Basic.Settings.Hotkeys.Pair="Key combinations shared with '%1' act as toggles"
 Basic.Settings.Hotkeys.Filter="Filter"
 Basic.Settings.Hotkeys.FilterByHotkey="Filter by Hotkey"
 Basic.Settings.Hotkeys.DuplicateWarning="This hotkey is shared by one or more other actions, click to show conflicts"
+Basic.Settings.Hotkeys.PleaseWait="Loading hotkeys, please wait..."
 
 # basic mode hotkeys
 Basic.Hotkeys.SelectScene="Switch to scene"

+ 19 - 0
UI/forms/OBSBasicSettings.ui

@@ -5692,6 +5692,25 @@
              <property name="bottomMargin">
               <number>9</number>
              </property>
+             <item row="0" column="0" colspan="2">
+              <widget class="QLabel" name="pleaseWaitLabel">
+               <property name="sizePolicy">
+                <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                 <horstretch>0</horstretch>
+                 <verstretch>0</verstretch>
+                </sizepolicy>
+               </property>
+               <property name="text">
+                <string>Basic.Settings.Hotkeys.PleaseWait</string>
+               </property>
+               <property name="scaledContents">
+                <bool>false</bool>
+               </property>
+               <property name="alignment">
+                <set>Qt::AlignCenter</set>
+               </property>
+              </widget>
+             </item>
             </layout>
            </widget>
           </widget>

+ 23 - 2
UI/window-basic-settings.cpp

@@ -3074,6 +3074,13 @@ void OBSBasicSettings::LoadHotkeySettings(obs_hotkey_id ignoreKey)
 	AddHotkeys(*hotkeysLayout, obs_service_get_name, services);
 
 	ScanDuplicateHotkeys(hotkeysLayout);
+
+	/* After this function returns the UI can still be unresponsive for a bit.
+	 * So by deferring the call to unsetCursor() to the Qt event loop it will
+	 * take until it has actually finished processing the created widgets
+	 * before the cursor is reset. */
+	QTimer::singleShot(1, this, &OBSBasicSettings::unsetCursor);
+	hotkeysLoaded = true;
 }
 
 void OBSBasicSettings::LoadSettings(bool changedOnly)
@@ -3088,8 +3095,6 @@ void OBSBasicSettings::LoadSettings(bool changedOnly)
 		LoadAudioSettings();
 	if (!changedOnly || videoChanged)
 		LoadVideoSettings();
-	if (!changedOnly || hotkeysChanged)
-		LoadHotkeySettings();
 	if (!changedOnly || a11yChanged)
 		LoadA11ySettings();
 	if (!changedOnly || advancedChanged)
@@ -3996,6 +4001,20 @@ void OBSBasicSettings::on_listWidget_itemSelectionChanged()
 	if (loading || row == pageIndex)
 		return;
 
+	if (!hotkeysLoaded && row == 5) {
+		setCursor(Qt::BusyCursor);
+		/* Look, I know this /feels/ wrong, but the specific issue we're dealing with
+		 * here means that the UI locks up immediately even when using "invokeMethod".
+		 * So the only way for the user to see the loading message on the page is to
+		 * give the Qt event loop a tiny bit of time to switch to the hotkey page,
+		 * and only then start loading. This could maybe be done by subclassing QWidget
+		 * for the hotkey page and then using showEvent() but I *really* don't want
+		 * to deal with that right now. I've got better things to do with my life
+		 * than to work around this god damn stupid issue for something we'll remove
+		 * soon enough anyway. So this solution it is. */
+		QTimer::singleShot(1, this, [&]() { LoadHotkeySettings(); });
+	}
+
 	pageIndex = row;
 }
 
@@ -4629,6 +4648,8 @@ bool OBSBasicSettings::ScanDuplicateHotkeys(QFormLayout *layout)
 
 void OBSBasicSettings::ReloadHotkeys(obs_hotkey_id ignoreKey)
 {
+	if (!hotkeysLoaded)
+		return;
 	LoadHotkeySettings(ignoreKey);
 }
 

+ 1 - 0
UI/window-basic-settings.hpp

@@ -125,6 +125,7 @@ private:
 	int sampleRateIndex = 0;
 	int channelIndex = 0;
 	bool llBufferingEnabled = false;
+	bool hotkeysLoaded = false;
 
 	int lastSimpleRecQualityIdx = 0;
 	int lastServiceIdx = -1;