From 08f23cc4249694f0a86aecf6eac545b5027e1796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 5 Dec 2020 22:07:39 +0100 Subject: [PATCH] Revert leasing logic --- .../Input/ConfineMouseTrackerTest.cs | 16 ++-------- osu.Game/Input/ConfineMouseTracker.cs | 31 ++++++------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/osu.Game.Tests/Input/ConfineMouseTrackerTest.cs b/osu.Game.Tests/Input/ConfineMouseTrackerTest.cs index 42f5209643..b90382488f 100644 --- a/osu.Game.Tests/Input/ConfineMouseTrackerTest.cs +++ b/osu.Game.Tests/Input/ConfineMouseTrackerTest.cs @@ -28,8 +28,6 @@ namespace osu.Game.Tests.Input setWindowModeTo(windowMode); setGameSideModeTo(OsuConfineMouseMode.Never); - gameSideConfineModeDisabled(false); - setLocalUserPlayingTo(false); frameworkSideModeIs(ConfineMouseMode.Never); @@ -44,8 +42,6 @@ namespace osu.Game.Tests.Input setWindowModeTo(windowMode); setGameSideModeTo(OsuConfineMouseMode.DuringGameplay); - gameSideConfineModeDisabled(false); - setLocalUserPlayingTo(false); frameworkSideModeIs(ConfineMouseMode.Never); @@ -60,8 +56,6 @@ namespace osu.Game.Tests.Input setWindowModeTo(windowMode); setGameSideModeTo(OsuConfineMouseMode.Always); - gameSideConfineModeDisabled(false); - setLocalUserPlayingTo(false); frameworkSideModeIs(ConfineMouseMode.Always); @@ -75,20 +69,18 @@ namespace osu.Game.Tests.Input setGameSideModeTo(OsuConfineMouseMode.Never); setWindowModeTo(WindowMode.Fullscreen); - gameSideConfineModeDisabled(true); setLocalUserPlayingTo(false); - frameworkSideModeIs(ConfineMouseMode.Always); + frameworkSideModeIs(ConfineMouseMode.Fullscreen); setLocalUserPlayingTo(true); - frameworkSideModeIs(ConfineMouseMode.Always); + frameworkSideModeIs(ConfineMouseMode.Fullscreen); setWindowModeTo(WindowMode.Windowed); // old state is restored gameSideModeIs(OsuConfineMouseMode.Never); frameworkSideModeIs(ConfineMouseMode.Never); - gameSideConfineModeDisabled(false); } private void setWindowModeTo(WindowMode mode) @@ -106,9 +98,5 @@ namespace osu.Game.Tests.Input private void frameworkSideModeIs(ConfineMouseMode mode) => AddAssert($"mode is {mode} framework-side", () => frameworkConfigManager.Get(FrameworkSetting.ConfineMouseMode) == mode); - - private void gameSideConfineModeDisabled(bool disabled) - => AddAssert($"game-side confine mode {(disabled ? "disabled" : "enabled")}", - () => Game.LocalConfig.GetBindable(OsuSetting.ConfineMouseMode).Disabled == disabled); } } diff --git a/osu.Game/Input/ConfineMouseTracker.cs b/osu.Game/Input/ConfineMouseTracker.cs index 739bfaadab..75d9c8debb 100644 --- a/osu.Game/Input/ConfineMouseTracker.cs +++ b/osu.Game/Input/ConfineMouseTracker.cs @@ -28,38 +28,27 @@ namespace osu.Game.Input { frameworkConfineMode = frameworkConfigManager.GetBindable(FrameworkSetting.ConfineMouseMode); frameworkWindowMode = frameworkConfigManager.GetBindable(FrameworkSetting.WindowMode); - frameworkWindowMode.BindValueChanged(_ => updateGameConfineMode()); + frameworkWindowMode.BindValueChanged(_ => updateConfineMode()); osuConfineMode = osuConfigManager.GetBindable(OsuSetting.ConfineMouseMode); localUserPlaying = game.LocalUserPlaying.GetBoundCopy(); - osuConfineMode.ValueChanged += _ => updateFrameworkConfineMode(); - localUserPlaying.BindValueChanged(_ => updateFrameworkConfineMode(), true); + osuConfineMode.ValueChanged += _ => updateConfineMode(); + localUserPlaying.BindValueChanged(_ => updateConfineMode(), true); } - 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() + private void updateConfineMode() { // 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: