@@ -151,29 +151,37 @@ public AppsListPage()
151151
152152 private void OnAppListPage_Loaded ( object sender , RoutedEventArgs e )
153153 {
154- Gamepad . GamepadAdded += onGamepadAdded ;
154+ Gamepad . GamepadAdded += OnGamepadAdded ;
155155 Gamepad . GamepadRemoved += OnGamepadRemoved ;
156156 }
157157
158158 private void OnGamepadRemoved ( object sender , Gamepad e )
159159 {
160+ Logger . WriteInformation ( "Controller disconnected" ) ;
160161 gamepad = null ;
162+ this . DispatcherQueue . TryEnqueue ( ( ) =>
163+ {
164+ App . MainWindow . SwitchMode ( MainWindow . AppMode . DESKTOP ) ;
165+ } ) ;
161166 }
162167
163- private void onGamepadAdded ( object sender , Gamepad e )
168+ private void OnGamepadAdded ( object sender , Gamepad e )
164169 {
170+ Logger . WriteInformation ( "Controller connected" ) ;
165171 gamepad = e ;
166- ListenGamepadInput ( ) ;
167172 this . DispatcherQueue . TryEnqueue ( ( ) =>
168173 {
169174 if ( appList . Children . Count > 0 )
170175 {
171176 appList . Children [ currentIndex ] . Focus ( FocusState . Keyboard ) ;
172177 }
178+ App . MainWindow . SwitchMode ( MainWindow . AppMode . CONTROLLER ) ;
173179 } ) ;
180+ ListenGamepadInput ( ) ;
174181 }
175182
176183
184+ // can we make this work everywhere, like in content dialogs?
177185 private async void ListenGamepadInput ( )
178186 {
179187 while ( gamepad != null )
@@ -183,9 +191,12 @@ private async void ListenGamepadInput()
183191 bool moveLeft = gamepadInput . LeftThumbstickX < - 0.5 || ( gamepadInput . Buttons & GamepadButtons . DPadLeft ) != 0 ;
184192 bool moveUp = gamepadInput . LeftThumbstickY > 0.5 || ( gamepadInput . Buttons & GamepadButtons . DPadUp ) != 0 ;
185193 bool moveDown = gamepadInput . LeftThumbstickY < - 0.5 || ( gamepadInput . Buttons & GamepadButtons . DPadDown ) != 0 ;
194+ bool start = ( gamepadInput . Buttons & GamepadButtons . Menu ) != 0 ; // start as in the button, not start package
195+ bool view = ( gamepadInput . Buttons & GamepadButtons . View ) != 0 ; // TODO: on click it should switch between the navigationview, bottom docked bar, and apps list (needs handling for other pages)
186196 bool actionClicked = ( gamepadInput . Buttons & GamepadButtons . A ) != 0 ;
187197
188-
198+ // feel like we should have like event listeners or whatever
199+ // actionClicked += whatever
189200 if ( actionClicked && inputProcessed )
190201 {
191202 inputProcessed = false ;
@@ -197,6 +208,19 @@ private async void ListenGamepadInput()
197208 } ) ;
198209 }
199210
211+ // disabled until controller support works
212+ // also pressing start twice will crash cuz 2 contentdialogs
213+ //if (start && inputProcessed)
214+ //{
215+ // inputProcessed = false;
216+ // this.DispatcherQueue.TryEnqueue(() =>
217+ // {
218+ // var appTile = appList.Children[currentIndex] as AppTile;
219+ // appTile.ShowControllerInteractDialog();
220+ // inputProcessed = true;
221+ // });
222+ //}
223+
200224 if ( ( moveRight || moveLeft || moveUp || moveDown ) && inputProcessed )
201225 {
202226 inputProcessed = false ;
@@ -213,7 +237,7 @@ private async void ListenGamepadInput()
213237 private void MoveFocus ( int xOffset , int yOffset )
214238 {
215239 bool firstInput = lastInput == 0 ;
216- if ( lastInput > DateTimeOffset . UtcNow . ToUnixTimeMilliseconds ( ) - 200 )
240+ if ( lastInput > DateTimeOffset . UtcNow . ToUnixTimeMilliseconds ( ) - 10 )
217241 {
218242 inputProcessed = true ;
219243 return ;
0 commit comments