diff --git a/windows/src/desktop/kmshell/main/initprog.pas b/windows/src/desktop/kmshell/main/initprog.pas index 3d0ea7675a..27d1ea95b5 100644 --- a/windows/src/desktop/kmshell/main/initprog.pas +++ b/windows/src/desktop/kmshell/main/initprog.pas @@ -526,12 +526,16 @@ begin fmMain, fmAbout: begin // I2720 FMutex := TKeymanMutex.Create('KeymanConfiguration'); - if FMutex.MutexOwned then Main else FocusConfiguration; + if FMutex.TakeOwnership + then Main + else FocusConfiguration; end; fmTextEditor: begin // I2720 FMutex := TKeymanMutex.Create('KeymanTextEditor'); - if FMutex.MutexOwned then OpenTextEditor else FocusTextEditor; + if FMutex.TakeOwnership + then OpenTextEditor + else FocusTextEditor; end; fmBaseKeyboard: // I4169 diff --git a/windows/src/desktop/kmshell/startup/UfrmSplash.pas b/windows/src/desktop/kmshell/startup/UfrmSplash.pas index 5a6cccd529..d10379fc3e 100644 --- a/windows/src/desktop/kmshell/startup/UfrmSplash.pas +++ b/windows/src/desktop/kmshell/startup/UfrmSplash.pas @@ -220,7 +220,7 @@ begin begin FMutex := TKeymanMutex.Create('KeymanSplash'); try - if not FMutex.MutexOwned then + if not FMutex.TakeOwnership then begin FocusSplash; // I2562 Exit; diff --git a/windows/src/engine/kmcomapi/com/system/keymancontrol.pas b/windows/src/engine/kmcomapi/com/system/keymancontrol.pas index 6b429b985e..4adf198844 100644 --- a/windows/src/engine/kmcomapi/com/system/keymancontrol.pas +++ b/windows/src/engine/kmcomapi/com/system/keymancontrol.pas @@ -281,7 +281,7 @@ function TKeymanControl.IsConfigurationOpen: WordBool; begin with TKeymanMutex.Create('KeymanConfiguration') do try - Result := MutexOwned; + Result := not TakeOwnership; finally Free; end; @@ -302,7 +302,7 @@ function TKeymanControl.IsTextEditorOpen: WordBool; begin with TKeymanMutex.Create('KeymanTextEditor') do try - Result := MutexOwned; + Result := not TakeOwnership; finally Free; end; diff --git a/windows/src/global/delphi/general/KeymanMutex.pas b/windows/src/global/delphi/general/KeymanMutex.pas index 4e9d92921a..4be88a189f 100644 --- a/windows/src/global/delphi/general/KeymanMutex.pas +++ b/windows/src/global/delphi/general/KeymanMutex.pas @@ -29,7 +29,8 @@ type public constructor Create(FName: string); destructor Destroy; override; - function MutexOwned: Boolean; + function TakeOwnership: Boolean; + function ReleaseOwnership: Boolean; end; implementation @@ -52,9 +53,14 @@ begin inherited Destroy; end; -function TKeymanMutex.MutexOwned: Boolean; +function TKeymanMutex.TakeOwnership: Boolean; begin Result := WaitForSingleObject(hMutex, 0) = WAIT_OBJECT_0; end; +function TKeymanMutex.ReleaseOwnership: Boolean; +begin + Result := ReleaseMutex(hMutex); +end; + end.