Debian Codegraph @

xbmc/windowing/win10/WinEventsWin10.cpp

raw
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "WinEventsWin10.h"
10
11 #include "GUIUserMessages.h"
12 #include "ServiceBroker.h"
13 #include "application/AppInboundProtocol.h"
14 #include "application/Application.h"
15 #include "guilib/GUIComponent.h"
16 #include "guilib/GUIWindowManager.h"
17 #include "input/actions/Action.h"
18 #include "input/actions/ActionIDs.h"
19 #include "input/mouse/MouseStat.h"
20 #include "input/touch/generic/GenericTouchInputHandler.h"
21 #include "interfaces/AnnouncementManager.h"
22 #include "messaging/ApplicationMessenger.h"
23 #include "rendering/dx/DeviceResources.h"
24 #include "rendering/dx/RenderContext.h"
25 #include "settings/AdvancedSettings.h"
26 #include "settings/SettingsComponent.h"
27 #include "utils/SystemInfo.h"
28 #include "utils/Variant.h"
29 #include "utils/log.h"
30 #include "windowing/windows/WinKeyMap.h"
31
32 #include "platform/win10/input/RemoteControlXbox.h"
33
34 #include <winrt/Windows.Devices.Input.h>
35
36 namespace winrt
37 {
38 using namespace Windows::Foundation;
39 }
40 using namespace winrt::Windows::ApplicationModel::Core;
41 using namespace winrt::Windows::Devices::Input;
42 using namespace winrt::Windows::Graphics::Display;
43 using namespace winrt::Windows::Media;
44 using namespace winrt::Windows::System;
45 using namespace winrt::Windows::UI::Core;
46 using namespace winrt::Windows::UI::Input;
47 using namespace winrt::Windows::UI::ViewManagement;
48
49 using namespace PERIPHERALS;
50
51 static winrt::Point GetScreenPoint(winrt::Point point)
52 {
53 auto dpi = DX::DeviceResources::Get()->GetDpi();
54 return winrt::Point(DX::ConvertDipsToPixels(point.X, dpi), DX::ConvertDipsToPixels(point.Y, dpi));
55 }
56
57 CWinEventsWin10::CWinEventsWin10() = default;
58 CWinEventsWin10::~CWinEventsWin10() = default;
59
60 void CWinEventsWin10::InitOSKeymap(void)
61 {
62 KODI::WINDOWING::WINDOWS::DIB_InitOSKeymap();
63 }
64
65 void CWinEventsWin10::MessagePush(XBMC_Event *newEvent)
66 {
67 // push input events in the queue they may init modal dialog which init
68 // deeper message loop and call the deeper MessagePump from there.
69 if ( newEvent->type == XBMC_KEYDOWN
70 || newEvent->type == XBMC_KEYUP
71 || newEvent->type == XBMC_MOUSEMOTION
72 || newEvent->type == XBMC_MOUSEBUTTONDOWN
73 || newEvent->type == XBMC_MOUSEBUTTONUP
74 || newEvent->type == XBMC_TOUCH)
75 {
76 m_events.push(*newEvent);
77 }
78 else
79 {
80 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
81 if (appPort)
82 appPort->OnEvent(*newEvent);
83 }
84 }
85
86 bool CWinEventsWin10::MessagePump()
87 {
88 bool ret = false;
89 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
90
91 // processes all pending events and exits immediately
92 CoreWindow::GetForCurrentThread().Dispatcher().ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
93
94 XBMC_Event pumpEvent;
95 while (m_events.try_pop(pumpEvent))
96 {
97 if (appPort)
98 ret |= appPort->OnEvent(pumpEvent);
99
100 if (pumpEvent.type == XBMC_MOUSEBUTTONUP)
101 CServiceBroker::GetGUI()->GetWindowManager().SendMessage(GUI_MSG_UNFOCUS_ALL, 0, 0, 0, 0);
102 }
103 return ret;
104 }
105
106 size_t CWinEventsWin10::GetQueueSize()
107 {
108 return m_events.unsafe_size();
109 }
110
111 void CWinEventsWin10::InitEventHandlers(const CoreWindow& window)
112 {
113 CWinEventsWin10::InitOSKeymap();
114
115 //window->SetPointerCapture();
116
117 // window
118 window.SizeChanged({ this, &CWinEventsWin10::OnWindowSizeChanged });
119 window.ResizeStarted({ this, &CWinEventsWin10::OnWindowResizeStarted });
120 window.ResizeCompleted({ this, &CWinEventsWin10::OnWindowResizeCompleted });
121 window.Closed({ this, &CWinEventsWin10::OnWindowClosed});
122 window.VisibilityChanged(CWinEventsWin10::OnVisibilityChanged);
123 window.Activated(CWinEventsWin10::OnWindowActivationChanged);
124 // mouse, touch and pen
125 window.PointerPressed({ this, &CWinEventsWin10::OnPointerPressed });
126 window.PointerMoved({ this, &CWinEventsWin10::OnPointerMoved });
127 window.PointerReleased({ this, &CWinEventsWin10::OnPointerReleased });
128 window.PointerExited({ this, &CWinEventsWin10::OnPointerExited });
129 window.PointerWheelChanged({ this, &CWinEventsWin10::OnPointerWheelChanged });
130 // keyboard
131 window.Dispatcher().AcceleratorKeyActivated({ this, &CWinEventsWin10::OnAcceleratorKeyActivated });
132 // display
133 DisplayInformation currentDisplayInformation = DisplayInformation::GetForCurrentView();
134 currentDisplayInformation.DpiChanged(CWinEventsWin10::OnDpiChanged);
135 currentDisplayInformation.OrientationChanged(CWinEventsWin10::OnOrientationChanged);
136 DisplayInformation::DisplayContentsInvalidated(CWinEventsWin10::OnDisplayContentsInvalidated);
137 // system
138 SystemNavigationManager sysNavManager = SystemNavigationManager::GetForCurrentView();
139 sysNavManager.BackRequested(CWinEventsWin10::OnBackRequested);
140
141 // requirement for backgroup playback
142 m_smtc = SystemMediaTransportControls::GetForCurrentView();
143 if (m_smtc)
144 {
145 m_smtc.IsPlayEnabled(true);
146 m_smtc.IsPauseEnabled(true);
147 m_smtc.IsStopEnabled(true);
148 m_smtc.IsRecordEnabled(true);
149 m_smtc.IsNextEnabled(true);
150 m_smtc.IsPreviousEnabled(true);
151 m_smtc.IsFastForwardEnabled(true);
152 m_smtc.IsRewindEnabled(true);
153 m_smtc.IsChannelUpEnabled(true);
154 m_smtc.IsChannelDownEnabled(true);
155 if (CSysInfo::GetWindowsDeviceFamily() != CSysInfo::WindowsDeviceFamily::Xbox)
156 {
157 m_smtc.ButtonPressed(CWinEventsWin10::OnSystemMediaButtonPressed);
158 }
159 m_smtc.IsEnabled(true);;
160 CServiceBroker::GetAnnouncementManager()->AddAnnouncer(this);
161 }
162 if (CSysInfo::GetWindowsDeviceFamily() == CSysInfo::WindowsDeviceFamily::Xbox)
163 {
164 m_remote = std::make_unique<CRemoteControlXbox>();
165 m_remote->Initialize();
166 }
167 }
168
169 void CWinEventsWin10::UpdateWindowSize()
170 {
171 auto size = DX::DeviceResources::Get()->GetOutputSize();
172
173 CLog::Log(LOGDEBUG, __FUNCTION__ ": window resize event {:f} x {:f} (as:{})", size.Width,
174 size.Height,
175 CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen ? "true"
176 : "false");
177
178 auto appView = ApplicationView::GetForCurrentView();
179 appView.SetDesiredBoundsMode(ApplicationViewBoundsMode::UseCoreWindow);
180
181 // seems app has lost FS mode it may occurs if an user use core window's button
182 if (CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen && !appView.IsFullScreenMode())
183 CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen = false;
184
185 XBMC_Event newEvent = {};
186 newEvent.type = XBMC_VIDEORESIZE;
187 newEvent.resize.width = size.Width;
188 newEvent.resize.height = size.Height;
189 newEvent.resize.scale = 1.0;
190 if (g_application.GetRenderGUI() && !DX::Windowing()->IsAlteringWindow() &&
191 newEvent.resize.width > 0 && newEvent.resize.height > 0)
192 MessagePush(&newEvent);
193 }
194
195 void CWinEventsWin10::OnResize(float width, float height)
196 {
197 CLog::Log(LOGDEBUG, __FUNCTION__": window size changed.");
198 m_logicalWidth = width;
199 m_logicalHeight = height;
200 m_bResized = true;
201
202 if (m_sizeChanging)
203 return;
204
205 HandleWindowSizeChanged();
206 }
207
208 // Window event handlers.
209 void CWinEventsWin10::OnWindowSizeChanged(const CoreWindow&, const WindowSizeChangedEventArgs& args)
210 {
211 OnResize(args.Size().Width, args.Size().Height);
212 }
213
214 void CWinEventsWin10::OnWindowResizeStarted(const CoreWindow& sender, const winrt::IInspectable&)
215 {
216 CLog::Log(LOGDEBUG, __FUNCTION__": window resize started.");
217 m_logicalPosX = sender.Bounds().X;
218 m_logicalPosY = sender.Bounds().Y;
219 m_sizeChanging = true;
220 }
221
222 void CWinEventsWin10::OnWindowResizeCompleted(const CoreWindow& sender, const winrt::IInspectable&)
223 {
224 CLog::Log(LOGDEBUG, __FUNCTION__": window resize completed.");
225 m_sizeChanging = false;
226
227 if (m_logicalPosX != sender.Bounds().X || m_logicalPosY != sender.Bounds().Y)
228 m_bMoved = true;
229
230 HandleWindowSizeChanged();
231 }
232
233 void CWinEventsWin10::HandleWindowSizeChanged()
234 {
235 CLog::Log(LOGDEBUG, __FUNCTION__": window size/move handled.");
236 if (m_bMoved)
237 {
238 // it will get position from CoreWindow
239 DX::Windowing()->OnMove(0, 0);
240 }
241 if (m_bResized)
242 {
243 DX::Windowing()->OnResize(m_logicalWidth, m_logicalHeight);
244 UpdateWindowSize();
245 }
246 m_bResized = false;
247 m_bMoved = false;
248 }
249
250 void CWinEventsWin10::OnVisibilityChanged(const CoreWindow& sender, const VisibilityChangedEventArgs& args)
251 {
252 bool active = g_application.GetRenderGUI();
253 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
254 if (appPort)
255 appPort->SetRenderGUI(args.Visible());
256
257 if (g_application.GetRenderGUI() != active)
258 DX::Windowing()->NotifyAppActiveChange(g_application.GetRenderGUI());
259 CLog::Log(LOGDEBUG, __FUNCTION__ ": window is {}",
260 g_application.GetRenderGUI() ? "shown" : "hidden");
261 }
262
263 void CWinEventsWin10::OnWindowActivationChanged(const CoreWindow& sender, const WindowActivatedEventArgs& args)
264 {
265 bool active = g_application.GetRenderGUI();
266 if (args.WindowActivationState() == CoreWindowActivationState::Deactivated)
267 {
268 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
269 if (appPort)
270 appPort->SetRenderGUI(DX::Windowing()->WindowedMode());
271 }
272 else if (args.WindowActivationState() == CoreWindowActivationState::PointerActivated
273 || args.WindowActivationState() == CoreWindowActivationState::CodeActivated)
274 {
275 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
276 if (appPort)
277 appPort->SetRenderGUI(true);
278 }
279 if (g_application.GetRenderGUI() != active)
280 DX::Windowing()->NotifyAppActiveChange(g_application.GetRenderGUI());
281
282 if (CServiceBroker::IsLoggingUp())
283 CLog::Log(LOGDEBUG, __FUNCTION__ ": window is {}",
284 g_application.GetRenderGUI() ? "active" : "inactive");
285 }
286
287 void CWinEventsWin10::OnWindowClosed(const CoreWindow& sender, const CoreWindowEventArgs& args)
288 {
289 // send quit command to the application if it's still running
290 if (!g_application.m_bStop)
291 {
292 XBMC_Event newEvent = {};
293 newEvent.type = XBMC_QUIT;
294 MessagePush(&newEvent);
295 }
296 }
297
298 void CWinEventsWin10::OnPointerPressed(const CoreWindow&, const PointerEventArgs& args)
299 {
300 XBMC_Event newEvent = {};
301
302 PointerPoint point = args.CurrentPoint();
303 auto position = GetScreenPoint(point.Position());
304
305 if (point.PointerDevice().PointerDeviceType() == PointerDeviceType::Touch)
306 {
307 CGenericTouchInputHandler::GetInstance().HandleTouchInput(TouchInputDown, position.X, position.Y, point.Timestamp(), 0, 10);
308 return;
309 }
310 else
311 {
312 newEvent.type = XBMC_MOUSEBUTTONDOWN;
313 newEvent.button.x = position.X;
314 newEvent.button.y = position.Y;
315 if (point.PointerDevice().PointerDeviceType() == PointerDeviceType::Mouse)
316 {
317 if (point.Properties().IsLeftButtonPressed())
318 newEvent.button.button = XBMC_BUTTON_LEFT;
319 else if (point.Properties().IsMiddleButtonPressed())
320 newEvent.button.button = XBMC_BUTTON_MIDDLE;
321 else if (point.Properties().IsRightButtonPressed())
322 newEvent.button.button = XBMC_BUTTON_RIGHT;
323 }
324 else if (point.PointerDevice().PointerDeviceType() == PointerDeviceType::Pen)
325 {
326 // pen
327 // TODO
328 }
329 }
330 MessagePush(&newEvent);
331 }
332
333 void CWinEventsWin10::OnPointerMoved(const CoreWindow&, const PointerEventArgs& args)
334 {
335 PointerPoint point = args.CurrentPoint();
336 auto position = GetScreenPoint(point.Position());
337
338 if (point.PointerDevice().PointerDeviceType() == PointerDeviceType::Touch)
339 {
340 if (point.IsInContact())
341 {
342 CGenericTouchInputHandler::GetInstance().UpdateTouchPointer(0, position.X, position.Y, point.Timestamp(), 10.f);
343 CGenericTouchInputHandler::GetInstance().HandleTouchInput(TouchInputMove, position.X, position.Y, point.Timestamp(), 0, 10.f);
344 }
345 return;
346 }
347
348 XBMC_Event newEvent = {};
349 newEvent.type = XBMC_MOUSEMOTION;
350 newEvent.motion.x = position.X;
351 newEvent.motion.y = position.Y;
352 MessagePush(&newEvent);
353 }
354
355 void CWinEventsWin10::OnPointerReleased(const CoreWindow&, const PointerEventArgs& args)
356 {
357 PointerPoint point = args.CurrentPoint();
358 auto position = GetScreenPoint(point.Position());
359
360 if (point.PointerDevice().PointerDeviceType() == PointerDeviceType::Touch)
361 {
362 CGenericTouchInputHandler::GetInstance().HandleTouchInput(TouchInputUp, position.X, position.Y, point.Timestamp(), 0, 10);
363 return;
364 }
365
366 XBMC_Event newEvent = {};
367 newEvent.type = XBMC_MOUSEBUTTONUP;
368 newEvent.button.x = position.X;
369 newEvent.button.y = position.Y;
370
371 if (point.Properties().PointerUpdateKind() == PointerUpdateKind::LeftButtonReleased)
372 newEvent.button.button = XBMC_BUTTON_LEFT;
373 else if (point.Properties().PointerUpdateKind() == PointerUpdateKind::MiddleButtonReleased)
374 newEvent.button.button = XBMC_BUTTON_MIDDLE;
375 else if (point.Properties().PointerUpdateKind() == PointerUpdateKind::RightButtonReleased)
376 newEvent.button.button = XBMC_BUTTON_RIGHT;
377
378 MessagePush(&newEvent);
379 }
380
381 void CWinEventsWin10::OnPointerExited(const CoreWindow&, const PointerEventArgs& args)
382 {
383 const PointerPoint& point = args.CurrentPoint();
384 auto position = GetScreenPoint(point.Position());
385
386 if (point.PointerDevice().PointerDeviceType() == PointerDeviceType::Touch)
387 {
388 CGenericTouchInputHandler::GetInstance().HandleTouchInput(TouchInputAbort, position.X, position.Y, point.Timestamp(), 0, 10);
389 }
390 }
391
392 void CWinEventsWin10::OnPointerWheelChanged(const CoreWindow&, const PointerEventArgs& args)
393 {
394 XBMC_Event newEvent = {};
395 newEvent.type = XBMC_MOUSEBUTTONDOWN;
396 newEvent.button.x = args.CurrentPoint().Position().X;
397 newEvent.button.y = args.CurrentPoint().Position().Y;
398 newEvent.button.button = args.CurrentPoint().Properties().MouseWheelDelta() > 0 ? XBMC_BUTTON_WHEELUP : XBMC_BUTTON_WHEELDOWN;
399 MessagePush(&newEvent);
400 newEvent.type = XBMC_MOUSEBUTTONUP;
401 MessagePush(&newEvent);
402 }
403
404 void CWinEventsWin10::Kodi_KeyEvent(unsigned int vkey,
405 uint32_t scancode,
406 unsigned keycode,
407 bool isDown)
408 {
409 using State = CoreVirtualKeyStates;
410
411 XBMC_keysym keysym = {};
412 keysym.scancode = scancode;
413 keysym.sym = KODI::WINDOWING::WINDOWS::VK_keymap[vkey];
414 keysym.unicode = keycode;
415
416 auto window = CoreWindow::GetForCurrentThread();
417
418 uint16_t mod = (uint16_t)XBMCKMOD_NONE;
419 // If left control and right alt are down this usually means that AltGr is down
420 if ((window.GetKeyState(VirtualKey::LeftControl) & State::Down) == State::Down
421 && (window.GetKeyState(VirtualKey::RightMenu) & State::Down) == State::Down)
422 {
423 mod |= XBMCKMOD_MODE;
424 mod |= XBMCKMOD_MODE;
425 }
426 else
427 {
428 if ((window.GetKeyState(VirtualKey::LeftControl) & State::Down) == State::Down)
429 mod |= XBMCKMOD_LCTRL;
430 if ((window.GetKeyState(VirtualKey::RightMenu) & State::Down) == State::Down)
431 mod |= XBMCKMOD_RALT;
432 }
433
434 // Check the remaining modifiers
435 if ((window.GetKeyState(VirtualKey::LeftShift) & State::Down) == State::Down)
436 mod |= XBMCKMOD_LSHIFT;
437 if ((window.GetKeyState(VirtualKey::RightShift) & State::Down) == State::Down)
438 mod |= XBMCKMOD_RSHIFT;
439 if ((window.GetKeyState(VirtualKey::RightControl) & State::Down) == State::Down)
440 mod |= XBMCKMOD_RCTRL;
441 if ((window.GetKeyState(VirtualKey::LeftMenu) & State::Down) == State::Down)
442 mod |= XBMCKMOD_LALT;
443 if ((window.GetKeyState(VirtualKey::LeftWindows) & State::Down) == State::Down)
444 mod |= XBMCKMOD_LSUPER;
445 if ((window.GetKeyState(VirtualKey::RightWindows) & State::Down) == State::Down)
446 mod |= XBMCKMOD_LSUPER;
447
448 keysym.mod = static_cast<XBMCMod>(mod);
449
450 XBMC_Event newEvent = {};
451 newEvent.type = isDown ? XBMC_KEYDOWN : XBMC_KEYUP;
452 newEvent.key.keysym = keysym;
453 MessagePush(&newEvent);
454 }
455
456 void CWinEventsWin10::OnAcceleratorKeyActivated(const CoreDispatcher&, const AcceleratorKeyEventArgs& args)
457 {
458 static auto lockedState = CoreVirtualKeyStates::Locked;
459 static VirtualKey keyStore = VirtualKey::None;
460
461 // skip if device is remote control
462 if (m_remote && m_remote->IsRemoteDevice(args.DeviceId().c_str()))
463 return;
464
465 bool isDown = false;
466 unsigned keyCode = 0;
467 unsigned vk = static_cast<unsigned>(args.VirtualKey());
468
469 auto window = CoreWindow::GetForCurrentThread();
470 bool numLockLocked = ((window.GetKeyState(VirtualKey::NumberKeyLock) & lockedState) == lockedState);
471
472 switch (args.EventType())
473 {
474 case CoreAcceleratorKeyEventType::KeyDown:
475 case CoreAcceleratorKeyEventType::SystemKeyDown:
476 {
477 if ( (vk == 0x08) // VK_BACK
478 || (vk == 0x09) // VK_TAB
479 || (vk == 0x0C) // VK_CLEAR
480 || (vk == 0x0D) // VK_RETURN
481 || (vk == 0x1B) // VK_ESCAPE
482 || (vk == 0x20) // VK_SPACE
483 || (vk >= 0x30 && vk <= 0x39) // numeric keys
484 || (vk >= 0x41 && vk <= 0x5A) // alphabetic keys
485 || (vk >= 0x60 && vk <= 0x69 && numLockLocked) // keypad numeric (if numlock is on)
486 || (vk >= 0x6A && vk <= 0x6F) // keypad keys except numeric
487 || (vk >= 0x92 && vk <= 0x96) // OEM specific
488 || (vk >= 0xBA && vk <= 0xC0) // OEM specific
489 || (vk >= 0xDB && vk <= 0xDF) // OEM specific
490 || (vk >= 0xE1 && vk <= 0xF5 && vk != 0xE5 && vk != 0xE7 && vk != 0xE8) // OEM specific
491 )
492 {
493 // store this for character events, because VirtualKey is key code on character event.
494 keyStore = args.VirtualKey();
495 return;
496 }
497 isDown = true;
498 break;
499 }
500 case CoreAcceleratorKeyEventType::KeyUp:
501 case CoreAcceleratorKeyEventType::SystemKeyUp:
502 break;
503 case CoreAcceleratorKeyEventType::Character:
504 case CoreAcceleratorKeyEventType::SystemCharacter:
505 case CoreAcceleratorKeyEventType::UnicodeCharacter:
506 case CoreAcceleratorKeyEventType::DeadCharacter:
507 case CoreAcceleratorKeyEventType::SystemDeadCharacter:
508 {
509 // VirtualKey is KeyCode
510 keyCode = static_cast<unsigned>(args.VirtualKey());
511 // rewrite vk with stored value
512 vk = static_cast<unsigned>(keyStore);
513 // reset stored value
514 keyStore = VirtualKey::None;
515 isDown = true;
516 }
517 default:
518 break;
519 }
520
521 Kodi_KeyEvent(vk, args.KeyStatus().ScanCode, keyCode, isDown);
522 args.Handled(true);
523 }
524
525 // DisplayInformation event handlers.
526 void CWinEventsWin10::OnDpiChanged(const DisplayInformation& sender, const winrt::IInspectable&)
527 {
528 // Note: The value for LogicalDpi retrieved here may not match the effective DPI of the app
529 // if it is being scaled for high resolution devices. Once the DPI is set on DeviceResources,
530 // you should always retrieve it using the GetDpi method.
531 // See DeviceResources.cpp for more details.
532 //critical_section::scoped_lock lock(m_deviceResources->GetCriticalSection());
533 RECT resizeRect = { 0,0,0,0 };
534 DX::Windowing()->DPIChanged(sender.LogicalDpi(), resizeRect);
535 CGenericTouchInputHandler::GetInstance().SetScreenDPI(DX::DisplayMetrics::Dpi100);
536 }
537
538 void CWinEventsWin10::OnOrientationChanged(const DisplayInformation&, const winrt::IInspectable&)
539 {
540 //critical_section::scoped_lock lock(m_deviceResources->GetCriticalSection());
541 //m_deviceResources->SetCurrentOrientation(sender->CurrentOrientation);
542
543 //auto size = DX::DeviceResources::Get()->GetOutputSize();
544 //UpdateWindowSize(size.Width, size.Height);
545 }
546
547 void CWinEventsWin10::OnDisplayContentsInvalidated(const DisplayInformation&, const winrt::IInspectable&)
548 {
549 CLog::Log(LOGDEBUG, __FUNCTION__": onevent.");
550 DX::DeviceResources::Get()->ValidateDevice();
551 }
552
553 void CWinEventsWin10::OnBackRequested(const winrt::IInspectable&, const BackRequestedEventArgs& args)
554 {
555 // handle this only on windows mobile
556 if (CSysInfo::GetWindowsDeviceFamily() == CSysInfo::WindowsDeviceFamily::Mobile)
557 {
558 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
559 static_cast<void*>(new CAction(ACTION_NAV_BACK)));
560 }
561 args.Handled(true);
562 }
563
564 void CWinEventsWin10::OnSystemMediaButtonPressed(const SystemMediaTransportControls&, const SystemMediaTransportControlsButtonPressedEventArgs& args)
565 {
566 int action = ACTION_NONE;
567 switch (args.Button())
568 {
569 case SystemMediaTransportControlsButton::ChannelDown:
570 action = ACTION_CHANNEL_DOWN;
571 break;
572 case SystemMediaTransportControlsButton::ChannelUp:
573 action = ACTION_CHANNEL_UP;
574 break;
575 case SystemMediaTransportControlsButton::FastForward:
576 action = ACTION_PLAYER_FORWARD;
577 break;
578 case SystemMediaTransportControlsButton::Rewind:
579 action = ACTION_PLAYER_REWIND;
580 break;
581 case SystemMediaTransportControlsButton::Next:
582 action = ACTION_NEXT_ITEM;
583 break;
584 case SystemMediaTransportControlsButton::Previous:
585 action = ACTION_PREV_ITEM;
586 break;
587 case SystemMediaTransportControlsButton::Pause:
588 case SystemMediaTransportControlsButton::Play:
589 action = ACTION_PLAYER_PLAYPAUSE;
590 break;
591 case SystemMediaTransportControlsButton::Stop:
592 action = ACTION_STOP;
593 break;
594 case SystemMediaTransportControlsButton::Record:
595 action = ACTION_RECORD;
596 break;
597 default:
598 break;
599 }
600 if (action != ACTION_NONE)
601 {
602 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
603 static_cast<void*>(new CAction(action)));
604 }
605 }
606
607 void CWinEventsWin10::Announce(ANNOUNCEMENT::AnnouncementFlag flag,
608 const std::string& sender,
609 const std::string& message,
610 const CVariant& data)
611 {
612 if (flag & ANNOUNCEMENT::Player)
613 {
614 double speed = 1.0;
615 if (data.isMember("player") && data["player"].isMember("speed"))
616 speed = data["player"]["speed"].asDouble(1.0);
617
618 bool changed = false;
619 MediaPlaybackStatus status = MediaPlaybackStatus::Changing;
620
621 if (message == "OnPlay" || message == "OnResume")
622 {
623 changed = true;
624 status = MediaPlaybackStatus::Playing;
625 }
626 else if (message == "OnStop")
627 {
628 changed = true;
629 status = MediaPlaybackStatus::Stopped;
630 }
631 else if (message == "OnPause")
632 {
633 changed = true;
634 status = MediaPlaybackStatus::Paused;
635 }
636 else if (message == "OnSpeedChanged")
637 {
638 changed = true;
639 status = speed != 0.0 ? MediaPlaybackStatus::Playing : MediaPlaybackStatus::Paused;
640 }
641
642 if (changed)
643 {
644 try
645 {
646 auto dispatcher = CoreApplication::MainView().Dispatcher();
647 if (dispatcher)
648 {
649 dispatcher.RunAsync(CoreDispatcherPriority::Normal, DispatchedHandler([status, speed]
650 {
651 auto smtc = SystemMediaTransportControls::GetForCurrentView();
652 if (!smtc)
653 return;
654
655 smtc.PlaybackStatus(status);
656 smtc.PlaybackRate(speed);
657 }));
658 }
659 }
660 catch (const winrt::hresult_error&)
661 {
662 }
663 }
664 }
665 }