From 0a745144e398c897d31293e12b0e0cc1befd9545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 5 Dec 2020 13:11:52 +0100 Subject: [PATCH] Disable confine mode dropdown when full-screen After hard-locking the mouse confine mode to `Always` in full-screen to prevent confine issues from popping up, the confine mode dropdown in settings had confusing UX due to seemingly having no effect when full-screen. --- osu.Game/Input/ConfineMouseTracker.cs | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/osu.Game/Input/ConfineMouseTracker.cs b/osu.Game/Input/ConfineMouseTracker.cs index 75d9c8debb..739bfaadab 100644 --- a/osu.Game/Input/ConfineMouseTracker.cs +++ b/osu.Game/Input/ConfineMouseTracker.cs @@ -28,27 +28,38 @@ namespace osu.Game.Input { frameworkConfineMode = frameworkConfigManager.GetBindable(FrameworkSetting.ConfineMouseMode); frameworkWindowMode = frameworkConfigManager.GetBindable(FrameworkSetting.WindowMode); - frameworkWindowMode.BindValueChanged(_ => updateConfineMode()); + frameworkWindowMode.BindValueChanged(_ => updateGameConfineMode()); osuConfineMode = osuConfigManager.GetBindable(OsuSetting.ConfineMouseMode); localUserPlaying = game.LocalUserPlaying.GetBoundCopy(); - osuConfineMode.ValueChanged += _ => updateConfineMode(); - localUserPlaying.BindValueChanged(_ => updateConfineMode(), true); + osuConfineMode.ValueChanged += _ => updateFrameworkConfineMode(); + localUserPlaying.BindValueChanged(_ => updateFrameworkConfineMode(), true); } - private void updateConfineMode() + private LeasedBindable leasedOsuConfineMode; + + private void updateGameConfineMode() + { + if (frameworkWindowMode.Value == WindowMode.Fullscreen && leasedOsuConfineMode == null) + { + leasedOsuConfineMode = osuConfineMode.BeginLease(true); + leasedOsuConfineMode.Value = OsuConfineMouseMode.Always; + } + + if (frameworkWindowMode.Value != WindowMode.Fullscreen && leasedOsuConfineMode != null) + { + leasedOsuConfineMode.Return(); + leasedOsuConfineMode = null; + } + } + + private void updateFrameworkConfineMode() { // confine mode is unavailable on some platforms if (frameworkConfineMode.Disabled) return; - if (frameworkWindowMode.Value == WindowMode.Fullscreen) - { - frameworkConfineMode.Value = ConfineMouseMode.Fullscreen; - return; - } - switch (osuConfineMode.Value) { case OsuConfineMouseMode.Never: