Merge pull request #2043 from Microsoft/petea/silentgazedetection

Don't obtain a GazeInputSourcePreview instance until it is known that…
This commit is contained in:
Jon Campbell 2018-05-01 11:29:49 -07:00 коммит произвёл GitHub
Родитель e502e1d143 6d840a5742
Коммит 3ee738530c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 14 добавлений и 10 удалений

Просмотреть файл

@ -69,8 +69,7 @@ GazePointer::GazePointer()
InitializeHistogram();
auto view = GazeInputSourcePreview::GetForCurrentView();
_watcher = view->CreateWatcher();
_watcher = GazeInputSourcePreview::CreateWatcher();
_watcher->Added += ref new TypedEventHandler<GazeDeviceWatcherPreview^, GazeDeviceWatcherAddedPreviewEventArgs^>(this, &GazePointer::OnDeviceAdded);
_watcher->Removed += ref new TypedEventHandler<GazeDeviceWatcherPreview^, GazeDeviceWatcherRemovedPreviewEventArgs^>(this, &GazePointer::OnDeviceRemoved);
_watcher->Start();
@ -83,6 +82,8 @@ void GazePointer::OnDeviceAdded(GazeDeviceWatcherPreview^ sender, GazeDeviceWatc
if (_deviceCount == 1)
{
IsDeviceAvailableChanged(nullptr, nullptr);
InitializeGazeInputSource();
}
}
@ -171,15 +172,18 @@ void GazePointer::InitializeHistogram()
void GazePointer::InitializeGazeInputSource()
{
_gazeInputSource = GazeInputSourcePreview::GetForCurrentView();
if (_gazeInputSource != nullptr)
if (_gazeInputSource == nullptr && _roots->Size != 0 && _deviceCount != 0)
{
_gazeEnteredToken = _gazeInputSource->GazeEntered += ref new TypedEventHandler<
GazeInputSourcePreview^, GazeEnteredPreviewEventArgs^>(this, &GazePointer::OnGazeEntered);
_gazeMovedToken = _gazeInputSource->GazeMoved += ref new TypedEventHandler<
GazeInputSourcePreview^, GazeMovedPreviewEventArgs^>(this, &GazePointer::OnGazeMoved);
_gazeExitedToken = _gazeInputSource->GazeExited += ref new TypedEventHandler<
GazeInputSourcePreview^, GazeExitedPreviewEventArgs^>(this, &GazePointer::OnGazeExited);
_gazeInputSource = GazeInputSourcePreview::GetForCurrentView();
if (_gazeInputSource != nullptr)
{
_gazeEnteredToken = _gazeInputSource->GazeEntered += ref new TypedEventHandler<
GazeInputSourcePreview^, GazeEnteredPreviewEventArgs^>(this, &GazePointer::OnGazeEntered);
_gazeMovedToken = _gazeInputSource->GazeMoved += ref new TypedEventHandler<
GazeInputSourcePreview^, GazeMovedPreviewEventArgs^>(this, &GazePointer::OnGazeMoved);
_gazeExitedToken = _gazeInputSource->GazeExited += ref new TypedEventHandler<
GazeInputSourcePreview^, GazeExitedPreviewEventArgs^>(this, &GazePointer::OnGazeExited);
}
}
}