QtBase  v6.3.1
qwin10helpers.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qwin10helpers.h"
41 
42 #include <QtCore/qdebug.h>
43 #include <winstring.h>
44 #include <roapi.h>
45 
46 #if defined(Q_CC_MINGW) || defined(Q_CC_CLANG)
47 # define HAS_UI_VIEW_SETTINGS_INTEROP
48 // Present from MSVC2015 + SDK 10 onwards
49 #elif (!defined(Q_CC_MSVC) || _MSC_VER >= 1900) && WINVER >= 0x0A00
50 # define HAS_UI_VIEW_SETTINGS_INTEROP
51 # define HAS_UI_VIEW_SETTINGS
52 #endif
53 
54 #include <inspectable.h>
55 
56 #ifdef HAS_UI_VIEW_SETTINGS
57 # include <windows.ui.viewmanagement.h>
58 #endif
59 
60 #ifdef HAS_UI_VIEW_SETTINGS_INTEROP
61 # include <uiviewsettingsinterop.h>
62 #endif
63 
64 #ifndef HAS_UI_VIEW_SETTINGS_INTEROP
65 MIDL_INTERFACE("3694dbf9-8f68-44be-8ff5-195c98ede8a6")
66 IUIViewSettingsInterop : public IInspectable
67 {
68 public:
69  virtual HRESULT STDMETHODCALLTYPE GetForWindow(
70  __RPC__in HWND hwnd,
71  __RPC__in REFIID riid,
72  __RPC__deref_out_opt void **ppv) = 0;
73 };
74 #endif // !HAS_UI_VIEW_SETTINGS_INTEROP
75 
76 #ifndef HAS_UI_VIEW_SETTINGS
77 namespace ABI {
78 namespace Windows {
79 namespace UI {
80 namespace ViewManagement {
81 
83 
84 MIDL_INTERFACE("C63657F6-8850-470D-88F8-455E16EA2C26")
85 IUIViewSettings : public IInspectable
86 {
87 public:
88  virtual HRESULT STDMETHODCALLTYPE get_UserInteractionMode(UserInteractionMode *value) = 0;
89 };
90 
91 } // namespace ViewManagement
92 } // namespace UI
93 } // namespace Windows
94 } // namespace ABI
95 #endif // HAS_UI_VIEW_SETTINGS
96 
98 
99 // Return tablet mode, note: Does not work for GetDesktopWindow().
100 bool qt_windowsIsTabletMode(HWND hwnd)
101 {
102  bool result = false;
103 
104  const wchar_t uiViewSettingsId[] = L"Windows.UI.ViewManagement.UIViewSettings";
105  HSTRING_HEADER uiViewSettingsIdRefHeader;
106  HSTRING uiViewSettingsIdHs = nullptr;
107  const auto uiViewSettingsIdLen = UINT32(sizeof(uiViewSettingsId) / sizeof(uiViewSettingsId[0]) - 1);
108  if (FAILED(WindowsCreateStringReference(uiViewSettingsId, uiViewSettingsIdLen, &uiViewSettingsIdRefHeader, &uiViewSettingsIdHs)))
109  return false;
110 
111  IUIViewSettingsInterop *uiViewSettingsInterop = nullptr;
112  // __uuidof(IUIViewSettingsInterop);
113  const GUID uiViewSettingsInteropRefId = {0x3694dbf9, 0x8f68, 0x44be,{0x8f, 0xf5, 0x19, 0x5c, 0x98, 0xed, 0xe8, 0xa6}};
114 
115  HRESULT hr = RoGetActivationFactory(uiViewSettingsIdHs, uiViewSettingsInteropRefId,
116  reinterpret_cast<void **>(&uiViewSettingsInterop));
117  if (FAILED(hr))
118  return false;
119 
120  // __uuidof(ABI::Windows::UI::ViewManagement::IUIViewSettings);
121  const GUID uiViewSettingsRefId = {0xc63657f6, 0x8850, 0x470d,{0x88, 0xf8, 0x45, 0x5e, 0x16, 0xea, 0x2c, 0x26}};
122  ABI::Windows::UI::ViewManagement::IUIViewSettings *viewSettings = nullptr;
123  hr = uiViewSettingsInterop->GetForWindow(hwnd, uiViewSettingsRefId,
124  reinterpret_cast<void **>(&viewSettings));
125  if (SUCCEEDED(hr)) {
127  hr = viewSettings->get_UserInteractionMode(&currentMode);
128  if (SUCCEEDED(hr))
129  result = currentMode == 1; // Touch, 1
130  viewSettings->Release();
131  }
132  uiViewSettingsInterop->Release();
133  return result;
134 }
135 
unsigned int UINT32
EGLOutputLayerEXT EGLint EGLAttrib value
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
IUIViewSettingsInterop __RPC__in REFIID riid
IUIViewSettingsInterop __RPC__in REFIID __RPC__deref_out_opt void ** ppv
QT_BEGIN_NAMESPACE bool qt_windowsIsTabletMode(HWND hwnd)
long HRESULT