VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h

Last change on this file was 106061, checked in by vboxsync, 7 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: UIKeyboardHandler.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIKeyboardHandler class declaration.
4 */
5
6/*
7 * Copyright (C) 2010-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef FEQT_INCLUDED_SRC_runtime_UIKeyboardHandler_h
29#define FEQT_INCLUDED_SRC_runtime_UIKeyboardHandler_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QMap>
36#include <QObject>
37
38/* GUI includes: */
39#include "UIExtraDataDefs.h"
40
41/* Other VBox includes: */
42#include <VBox/com/defs.h>
43
44/* External includes: */
45#ifdef VBOX_WS_MAC
46# include <Carbon/Carbon.h>
47# include <CoreFoundation/CFBase.h>
48#endif /* VBOX_WS_MAC */
49
50/* Forward declarations: */
51class QWidget;
52class UIActionPool;
53class UIMachine;
54class UIMachineLogic;
55class UIMachineView;
56class UIMachineWindow;
57#ifdef VBOX_WS_WIN
58class WinAltGrMonitor;
59#endif
60#ifdef VBOX_WS_NIX
61# include <xcb/xcb.h>
62#endif
63
64
65/* Delegate to control VM keyboard functionality: */
66class UIKeyboardHandler : public QObject
67{
68 Q_OBJECT;
69
70signals:
71
72 /** Notifies listeners about state-change. */
73 void sigStateChange(int iState);
74
75public:
76
77 /* Factory functions to create/destroy keyboard-handler: */
78 static UIKeyboardHandler* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
79 static void destroy(UIKeyboardHandler *pKeyboardHandler);
80
81 /* Prepare/cleanup listeners: */
82 void prepareListener(ulong uScreenId, UIMachineWindow *pMachineWindow);
83 void cleanupListener(ulong uScreenId);
84
85 /** Captures the keyboard for @a uScreenId. */
86 void captureKeyboard(ulong uScreenId);
87 /** Finalises keyboard capture. */
88 bool finaliseCaptureKeyboard();
89 /** Releases the keyboard. */
90 void releaseKeyboard();
91
92 void releaseAllPressedKeys(bool aReleaseHostKey = true);
93
94 /* Current keyboard state: */
95 int state() const;
96
97 /* Some getters required by side-code: */
98 bool isHostKeyPressed() const { return m_fHostComboPressed; }
99#ifdef VBOX_WS_MAC
100 bool isHostKeyAlone() const { return m_bIsHostComboAlone; }
101 bool isKeyboardGrabbed() const { return m_iKeyboardHookViewIndex != -1; }
102#endif /* VBOX_WS_MAC */
103
104#ifdef VBOX_WITH_DEBUGGER_GUI
105 /* For the debugger. */
106 void setDebuggerActive(bool aActive = true);
107#endif
108
109#ifdef VBOX_WS_WIN
110 /** Tells the keyboard event handler to skip host keyboard events.
111 * Used for HID LEDs sync when on Windows host a keyboard event
112 * is generated in order to change corresponding LED. */
113 void winSkipKeyboardEvents(bool fSkip);
114#endif /* VBOX_WS_WIN */
115
116 /** Qt5: Performs pre-processing of all the native events. */
117 bool nativeEventFilter(void *pMessage, ulong uScreenId);
118
119 /** Called whenever host key press/release scan codes are inserted to the guest.
120 * @a bPressed is true for press and false for release inserts. */
121 void setHostKeyComboPressedFlag(bool bPressed);
122
123protected slots:
124
125 /* Machine state-change handler: */
126 virtual void sltMachineStateChanged();
127
128 /** Finalises keyboard capture. */
129 void sltFinaliseCaptureKeyboard();
130
131protected:
132
133 /* Keyboard-handler constructor/destructor: */
134 UIKeyboardHandler(UIMachineLogic *pMachineLogic);
135 virtual ~UIKeyboardHandler();
136
137 /* Prepare helpers: */
138 virtual void prepareCommon();
139 virtual void loadSettings();
140
141 /* Cleanup helpers: */
142 //virtual void saveSettings() {}
143 virtual void cleanupCommon();
144
145 /* Common getters: */
146 UIMachineLogic *machineLogic() const { return m_pMachineLogic; }
147 UIActionPool *actionPool() const;
148 UIMachine *uimachine() const;
149
150 /* Event handler for registered machine-view(s): */
151 bool eventFilter(QObject *pWatchedObject, QEvent *pEvent) RT_OVERRIDE;
152
153#if defined(VBOX_WS_MAC)
154 /** Mac: Performs initial pre-processing of all the native keyboard events. */
155 static bool macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
156 /** Mac: Performs initial pre-processing of all the native keyboard events. */
157 bool macKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
158#elif defined(VBOX_WS_WIN)
159 /** Win: Performs initial pre-processing of all the native keyboard events. */
160 static LRESULT CALLBACK winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) RT_NOTHROW_PROTO;
161 /** Win: Performs initial pre-processing of all the native keyboard events. */
162 bool winKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);
163#endif /* VBOX_WS_WIN */
164
165 bool keyEventCADHandled(uint8_t uScan);
166 bool keyEventHandleNormal(int iKey, uint8_t uScan, int fFlags, LONG *pCodes, uint *puCodesCount);
167 bool keyEventHostComboHandled(int iKey, wchar_t *pUniKey, bool isHostComboStateChanged, bool *pfResult);
168 void keyEventHandleHostComboRelease(ulong uScreenId);
169 /* Separate function to handle most of existing keyboard-events: */
170 bool keyEvent(int iKey, uint8_t uScan, int fFlags, ulong uScreenId, wchar_t *pUniKey = 0);
171 bool processHotKey(int iHotKey, wchar_t *pUniKey);
172
173 /* Private helpers: */
174 void fixModifierState(LONG *piCodes, uint *puCount);
175 void saveKeyStates();
176 void sendChangedKeyStates();
177 bool isAutoCaptureDisabled();
178 void setAutoCaptureDisabled(bool fIsAutoCaptureDisabled);
179 bool autoCaptureSetGlobally();
180 bool viewHasFocus(ulong uScreenId);
181 bool isSessionRunning();
182 bool isSessionStuck();
183
184 UIMachineWindow* isItListenedWindow(QObject *pWatchedObject) const;
185 UIMachineView* isItListenedView(QObject *pWatchedObject) const;
186
187 /* Machine logic parent: */
188 UIMachineLogic *m_pMachineLogic;
189
190 /* Registered machine-window(s): */
191 QMap<ulong, UIMachineWindow*> m_windows;
192 /* Registered machine-view(s): */
193 QMap<ulong, UIMachineView*> m_views;
194
195 /* Other keyboard variables: */
196 int m_iKeyboardCaptureViewIndex;
197
198 uint8_t m_pressedKeys[128];
199 uint8_t m_pressedKeysCopy[128];
200
201 QMap<int, uint8_t> m_pressedHostComboKeys;
202
203 bool m_fKeyboardCaptured : 1;
204 bool m_fHostComboPressed : 1;
205 bool m_bIsHostComboAlone : 1;
206 bool m_bIsHostComboProcessed : 1;
207 bool m_fPassCADtoGuest : 1;
208 bool m_fHostKeyComboPressInserted : 1;
209 /** Whether the debugger is active.
210 * Currently only affects auto capturing. */
211 bool m_fDebuggerActive : 1;
212
213 /** Holds the keyboard hook view index. */
214 int m_iKeyboardHookViewIndex;
215
216#if defined(VBOX_WS_MAC)
217 /** Mac: Holds the current modifiers key mask. */
218 UInt32 m_uDarwinKeyModifiers;
219#elif defined(VBOX_WS_WIN)
220 /** Win: Currently this is used in winKeyboardEvent() only. */
221 bool m_fIsHostkeyInCapture;
222 /** Win: Holds whether the keyboard event filter should ignore keyboard events. */
223 bool m_fSkipKeyboardEvents;
224 /** Win: Holds the keyboard hook instance. */
225 HHOOK m_keyboardHook;
226 /** Win: Holds the object monitoring key event stream for problematic AltGr events. */
227 WinAltGrMonitor *m_pAltGrMonitor;
228 /** Win: Holds the keyboard handler reference to be accessible from the keyboard hook. */
229 static UIKeyboardHandler *m_spKeyboardHandler;
230#elif defined(VBOX_WS_NIX)
231 /** The root window at the time we grab the mouse buttons. */
232 xcb_window_t m_hButtonGrabWindow;
233#endif /* VBOX_WS_NIX */
234};
235
236#endif /* !FEQT_INCLUDED_SRC_runtime_UIKeyboardHandler_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette