2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "guilib/DispResource.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/SystemClock.h"
14 #include "windowing/WinSystem.h"
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;
25 /* Controls the way the window appears and behaves. */
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
34 static const char* window_state_names
[] =
38 "windowed fullscreen",
43 /* WINDOW_STATE restricted to fullscreen modes. */
44 enum WINDOW_FULLSCREEN_STATE
46 WINDOW_FULLSCREEN_STATE_FULLSCREEN
= WINDOW_STATE_FULLSCREEN
,
47 WINDOW_FULLSCREEN_STATE_FULLSCREEN_WINDOW
= WINDOW_STATE_FULLSCREEN_WINDOW
50 /* WINDOW_STATE restricted to windowed modes. */
51 enum WINDOW_WINDOW_STATE
53 WINDOW_WINDOW_STATE_WINDOWED
= WINDOW_STATE_WINDOWED
,
54 WINDOW_WINDOW_STATE_BORDERLESS
= WINDOW_STATE_BORDERLESS
57 struct MONITOR_DETAILS
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
76 class CWinSystemWin32
: public CWinSystemBase
80 virtual ~CWinSystemWin32();
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
;
95 bool Show(bool raise
= true) override
;
96 std::string
GetClipboardText() override
;
97 bool UseLimitedColor() override
;
98 bool HasSystemSdrPeakLuminance() override
;
101 std::unique_ptr
<CVideoSync
> GetVideoSync(void *clock
) override
;
103 bool SetFullScreen(bool fullScreen
, RESOLUTION_INFO
& res
, bool blankOtherDisplays
) override
;
105 std::vector
<std::string
> GetConnectedOutputs() override
;
108 HWND
GetHwnd() const { return m_hWnd
; }
109 bool IsAlteringWindow() const { return m_IsAlteringWindow
; }
110 void SetAlteringWindow(bool altering
) { m_IsAlteringWindow
= altering
; }
111 bool IsTogglingHDR() const { return m_IsTogglingHDR
; }
112 void SetTogglingHDR(bool toggling
);
113 virtual bool DPIChanged(WORD dpi
, RECT windowRect
) const;
114 bool IsMinimized() const { return m_bMinimized
; }
115 void SetMinimized(bool minimized
);
116 float GetGuiSdrPeakLuminance() const;
117 void CacheSystemSdrPeakLuminance();
119 void SetSizeMoveMode(bool mode
) { m_bSizeMoveEnabled
= mode
; }
120 bool IsInSizeMoveMode() const { return m_bSizeMoveEnabled
; }
122 // winevents override
123 bool MessagePump() override
;
126 bool CreateNewWindow(const std::string
& name
, bool fullScreen
, RESOLUTION_INFO
& res
) override
= 0;
127 virtual void UpdateStates(bool fullScreen
);
128 WINDOW_STATE
GetState(bool fullScreen
) const;
129 virtual void SetDeviceFullScreen(bool fullScreen
, RESOLUTION_INFO
& res
) = 0;
130 virtual void ReleaseBackBuffer() = 0;
131 virtual void CreateBackBuffer() = 0;
132 virtual void ResizeDeviceBuffers() = 0;
133 virtual bool IsStereoEnabled() = 0;
134 virtual void OnScreenChange(HMONITOR monitor
) = 0;
135 virtual void AdjustWindow(bool forceResize
= false);
136 void CenterCursor() const;
138 virtual void Register(IDispResource
*resource
);
139 virtual void Unregister(IDispResource
*resource
);
141 virtual bool ChangeResolution(const RESOLUTION_INFO
& res
, bool forceChange
= false);
142 virtual bool CreateBlankWindows();
143 virtual bool BlankNonActiveMonitors(bool bBlank
);
144 MONITOR_DETAILS
* GetDisplayDetails(const std::string
& name
);
145 MONITOR_DETAILS
* GetDisplayDetails(HMONITOR handle
);
146 void RestoreDesktopResolution(MONITOR_DETAILS
* details
);
147 RECT
ScreenRect(HMONITOR handle
);
148 void GetConnectedDisplays(std::vector
<MONITOR_DETAILS
>& outputs
);
152 \brief Adds a resolution to the list of resolutions if we don't already have it
153 \param res resolution to add.
155 static bool AddResolution(const RESOLUTION_INFO
&res
);
157 void OnDisplayLost();
158 void OnDisplayReset();
159 void OnDisplayBack();
160 void ResolutionChanged();
161 static void SetForegroundWindowInternal(HWND hWnd
);
162 static RECT
GetVirtualScreenRect();
164 * Retrieve the work area of the screen (exclude task bar and other occlusions)
166 RECT
GetScreenWorkArea(HMONITOR handle
) const;
168 * Retrieve size of the title bar and borders
169 * Add to coordinates to convert client coordinates to window coordinates
170 * Substract from coordinates to convert from window coordinates to client coordinates
172 RECT
GetNcAreaOffsets(DWORD dwStyle
, BOOL bMenu
, DWORD dwExStyle
) const;
177 std::vector
<HWND
> m_hBlankWindows
;
178 HINSTANCE m_hInstance
;
180 bool m_ValidWindowedPosition
;
181 bool m_IsAlteringWindow
;
182 bool m_IsTogglingHDR
{false};
184 CCriticalSection m_resourceSection
;
185 std::vector
<IDispResource
*> m_resources
;
186 bool m_delayDispReset
;
187 XbmcThreads::EndTime
<> m_dispResetTimer
;
189 WINDOW_STATE m_state
; // the state of the window
190 WINDOW_FULLSCREEN_STATE m_fullscreenState
; // the state of the window when in fullscreen
191 WINDOW_WINDOW_STATE m_windowState
; // the state of the window when in windowed
192 DWORD m_windowStyle
; // the style of the window
193 DWORD m_windowExStyle
; // the ex style of the window
196 bool m_bSizeMoveEnabled
= false;
197 bool m_bFirstResChange
= true;
198 std::unique_ptr
<CIRServerSuite
> m_irss
;
199 std::vector
<MONITOR_DETAILS
> m_displays
;
201 NOTIFYICONDATA m_trayIcon
= {};
203 static const char* SETTING_WINDOW_TOP
;
204 static const char* SETTING_WINDOW_LEFT
;
206 bool m_validSystemSdrPeakLuminance
{false};
207 float m_systemSdrPeakLuminance
{.0f
};