xbmc
WinSystemWin32.h
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 #pragma once
10 
11 #include "guilib/DispResource.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/SystemClock.h"
14 #include "windowing/WinSystem.h"
15 
16 #include <shellapi.h>
17 #include <vector>
18 
19 static const DWORD WINDOWED_STYLE = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
20 static const DWORD WINDOWED_EX_STYLE = NULL;
21 static const DWORD FULLSCREEN_WINDOW_STYLE = WS_POPUP | WS_SYSMENU | WS_CLIPCHILDREN;
22 static const DWORD FULLSCREEN_WINDOW_EX_STYLE = WS_EX_APPWINDOW;
23 static const UINT ID_TIMER_HDR = 34U;
24 
25 /* Controls the way the window appears and behaves. */
26 enum WINDOW_STATE
27 {
28  WINDOW_STATE_FULLSCREEN = 1, // Exclusive fullscreen
29  WINDOW_STATE_FULLSCREEN_WINDOW, // Non-exclusive fullscreen window
30  WINDOW_STATE_WINDOWED, //Movable window with border
31  WINDOW_STATE_BORDERLESS //Non-movable window with no border
32 };
33 
34 static const char* window_state_names[] =
35 {
36  "unknown",
37  "true fullscreen",
38  "windowed fullscreen",
39  "windowed",
40  "borderless"
41 };
42 
43 /* WINDOW_STATE restricted to fullscreen modes. */
44 enum WINDOW_FULLSCREEN_STATE
45 {
46  WINDOW_FULLSCREEN_STATE_FULLSCREEN = WINDOW_STATE_FULLSCREEN,
47  WINDOW_FULLSCREEN_STATE_FULLSCREEN_WINDOW = WINDOW_STATE_FULLSCREEN_WINDOW
48 };
49 
50 /* WINDOW_STATE restricted to windowed modes. */
51 enum WINDOW_WINDOW_STATE
52 {
53  WINDOW_WINDOW_STATE_WINDOWED = WINDOW_STATE_WINDOWED,
54  WINDOW_WINDOW_STATE_BORDERLESS = WINDOW_STATE_BORDERLESS
55 };
56 
57 struct MONITOR_DETAILS
58 {
59  int ScreenWidth;
60  int ScreenHeight;
61  int RefreshRate;
62  int Bpp;
63  int DisplayId;
64  bool Interlaced;
65  bool IsPrimary;
66 
67  HMONITOR hMonitor;
68  std::wstring MonitorNameW;
69  std::wstring CardNameW;
70  std::wstring DeviceNameW;
71  std::wstring DeviceStringW; // GDI device, for migration of the monitor setting from Kodi < 21
72 };
73 
74 class CIRServerSuite;
75 
77 {
78 public:
80  virtual ~CWinSystemWin32();
81 
82  // CWinSystemBase overrides
83  bool InitWindowSystem() override;
84  bool DestroyWindowSystem() override;
85  bool ResizeWindow(int newWidth, int newHeight, int newLeft, int newTop) override;
86  void FinishWindowResize(int newWidth, int newHeight) override;
87  void UpdateResolutions() override;
88  bool CenterWindow() override;
89  virtual void NotifyAppFocusChange(bool bGaining) override;
90  void ShowOSMouse(bool show) override;
91  bool HasInertialGestures() override { return true; }//if win32 has touchscreen - it uses the win32 gesture api for inertial scrolling
92  bool Minimize() override;
93  bool Restore() override;
94  bool Hide() override;
95  bool Show(bool raise = true) override;
96  std::string GetClipboardText() override;
97  bool UseLimitedColor() override;
98 
99  // videosync
100  std::unique_ptr<CVideoSync> GetVideoSync(void *clock) override;
101 
102  bool SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) override;
103 
104  std::vector<std::string> GetConnectedOutputs() override;
105 
106  // CWinSystemWin32
107  HWND GetHwnd() const { return m_hWnd; }
108  bool IsAlteringWindow() const { return m_IsAlteringWindow; }
109  void SetAlteringWindow(bool altering) { m_IsAlteringWindow = altering; }
110  bool IsTogglingHDR() const { return m_IsTogglingHDR; }
111  void SetTogglingHDR(bool toggling);
112  virtual bool DPIChanged(WORD dpi, RECT windowRect) const;
113  bool IsMinimized() const { return m_bMinimized; }
114  void SetMinimized(bool minimized);
115  int GetGuiSdrPeakLuminance() const;
116 
117  void SetSizeMoveMode(bool mode) { m_bSizeMoveEnabled = mode; }
118  bool IsInSizeMoveMode() const { return m_bSizeMoveEnabled; }
119 
120  // winevents override
121  bool MessagePump() override;
122 
123 protected:
124  bool CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res) override = 0;
125  virtual void UpdateStates(bool fullScreen);
126  WINDOW_STATE GetState(bool fullScreen) const;
127  virtual void SetDeviceFullScreen(bool fullScreen, RESOLUTION_INFO& res) = 0;
128  virtual void ReleaseBackBuffer() = 0;
129  virtual void CreateBackBuffer() = 0;
130  virtual void ResizeDeviceBuffers() = 0;
131  virtual bool IsStereoEnabled() = 0;
132  virtual void OnScreenChange(HMONITOR monitor) = 0;
133  virtual void AdjustWindow(bool forceResize = false);
134  void CenterCursor() const;
135 
136  virtual void Register(IDispResource *resource);
137  virtual void Unregister(IDispResource *resource);
138 
139  virtual bool ChangeResolution(const RESOLUTION_INFO& res, bool forceChange = false);
140  virtual bool CreateBlankWindows();
141  virtual bool BlankNonActiveMonitors(bool bBlank);
142  MONITOR_DETAILS* GetDisplayDetails(const std::string& name);
143  MONITOR_DETAILS* GetDisplayDetails(HMONITOR handle);
144  void RestoreDesktopResolution(MONITOR_DETAILS* details);
145  RECT ScreenRect(HMONITOR handle);
146  void GetConnectedDisplays(std::vector<MONITOR_DETAILS>& outputs);
147 
148 
153  static bool AddResolution(const RESOLUTION_INFO &res);
154 
155  void OnDisplayLost();
156  void OnDisplayReset();
157  void OnDisplayBack();
158  void ResolutionChanged();
159  static void SetForegroundWindowInternal(HWND hWnd);
160  static RECT GetVirtualScreenRect();
161 
162  HWND m_hWnd;
163  HMONITOR m_hMonitor;
164 
165  std::vector<HWND> m_hBlankWindows;
166  HINSTANCE m_hInstance;
167  HICON m_hIcon;
168  bool m_ValidWindowedPosition;
169  bool m_IsAlteringWindow;
170  bool m_IsTogglingHDR{false};
171 
172  CCriticalSection m_resourceSection;
173  std::vector<IDispResource*> m_resources;
174  bool m_delayDispReset;
175  XbmcThreads::EndTime<> m_dispResetTimer;
176 
177  WINDOW_STATE m_state; // the state of the window
178  WINDOW_FULLSCREEN_STATE m_fullscreenState; // the state of the window when in fullscreen
179  WINDOW_WINDOW_STATE m_windowState; // the state of the window when in windowed
180  DWORD m_windowStyle; // the style of the window
181  DWORD m_windowExStyle; // the ex style of the window
182  bool m_inFocus;
183  bool m_bMinimized;
184  bool m_bSizeMoveEnabled = false;
185  bool m_bFirstResChange = true;
186  std::unique_ptr<CIRServerSuite> m_irss;
187  std::vector<MONITOR_DETAILS> m_displays;
188 
189  NOTIFYICONDATA m_trayIcon = {};
190 
191  static const char* SETTING_WINDOW_TOP;
192  static const char* SETTING_WINDOW_LEFT;
193 };
194 
195 extern HWND g_hWnd;
196 
Definition: WinSystemWin10.h:53
Definition: WinSystem.h:44
Definition: SystemClock.h:31
Definition: DispResource.h:14
Provide info of a resolution.
Definition: Resolution.h:66
Definition: WinSystemWin32.h:76
#define U(j)
uj for division
Definition: bigint.c:73
Definition: IRServerSuite.h:20