VirtualBox

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

Last change on this file since 35740 was 35730, checked in by vboxsync, 13 years ago

FE/Qt: 5245: GUI support for complex host-key combinations. Initial build for Win/X11.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * UIKeyboardHandler class declaration
5 */
6
7/*
8 * Copyright (C) 2010 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ___UIKeyboardHandler_h___
20#define ___UIKeyboardHandler_h___
21
22/* Global includes */
23#include <QObject>
24#include <QMap>
25
26/* Local includes */
27#include "UIMachineDefs.h"
28#include "COMDefs.h"
29
30#ifdef Q_WS_MAC
31# include <CoreFoundation/CFBase.h>
32# include <Carbon/Carbon.h>
33#endif /* Q_WS_MAC */
34
35/* Global forwards */
36class QWidget;
37
38/* Local forwards */
39class CSession;
40class UISession;
41class UIMachineLogic;
42class UIMachineWindow;
43class UIMachineView;
44class VBoxGlobalSettings;
45#ifdef Q_WS_X11
46typedef union _XEvent XEvent;
47#endif /* Q_WS_X11 */
48
49/* Delegate to control VM keyboard functionality: */
50class UIKeyboardHandler : public QObject
51{
52 Q_OBJECT;
53
54public:
55
56 /* Factory functions to create/destroy keyboard-handler: */
57 static UIKeyboardHandler* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
58 static void destroy(UIKeyboardHandler *pKeyboardHandler);
59
60 /* Prepare/cleanup listeners: */
61 void prepareListener(ulong uIndex, UIMachineWindow *pMachineWindow);
62 void cleanupListener(ulong uIndex);
63
64 /* Commands to capture/release keyboard: */
65 void captureKeyboard(ulong uScreenId);
66 void releaseKeyboard();
67 void releaseAllPressedKeys(bool aReleaseHostKey = true);
68
69 /* Current keyboard state: */
70 int keyboardState() const;
71
72 /* Some getters required by side-code: */
73 bool isHostKeyPressed() const { return m_bIsHostComboPressed; }
74#ifdef Q_WS_MAC
75 bool isHostKeyAlone() const { return m_bIsHostComboAlone; }
76 bool isKeyboardGrabbed() const { return m_fKeyboardGrabbed; }
77#endif /* Q_WS_MAC */
78
79 /* External event-filters: */
80#if defined(Q_WS_WIN)
81 bool winEventFilter(MSG *pMsg, ulong uScreenId);
82#elif defined(Q_WS_X11)
83 bool x11EventFilter(XEvent *pEvent, ulong uScreenId);
84#endif
85
86signals:
87
88 /* Notifies listeners about keyboard state-change: */
89 void keyboardStateChanged(int iNewState);
90
91protected slots:
92
93 /* Machine state-change handler: */
94 virtual void sltMachineStateChanged();
95
96protected:
97
98 /* Keyboard-handler constructor/destructor: */
99 UIKeyboardHandler(UIMachineLogic *pMachineLogic);
100 virtual ~UIKeyboardHandler();
101
102 /* Prepare helpers: */
103 virtual void prepareCommon();
104 virtual void loadSettings();
105
106 /* Cleanup helpers: */
107 //virtual void saveSettings() {}
108 virtual void cleanupCommon();
109
110 /* Common getters: */
111 UIMachineLogic* machineLogic() const;
112 UISession* uisession() const;
113 CSession& session() const;
114
115 /* Event handler for registered machine-view(s): */
116 bool eventFilter(QObject *pWatchedObject, QEvent *pEvent);
117#if defined(Q_WS_WIN)
118 static LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
119 bool winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);
120#elif defined(Q_WS_MAC)
121 void darwinGrabKeyboardEvents(bool fGrab);
122 bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
123 static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
124#endif
125
126 /* Separate function to handle most of existing keyboard-events: */
127 bool keyEvent(int iKey, uint8_t uScan, int fFlags, ulong uScreenId, wchar_t *pUniKey = 0);
128 bool processHotKey(int iHotKey, wchar_t *pUniKey);
129
130 /* Private helpers: */
131 void fixModifierState(LONG *piCodes, uint *puCount);
132 void saveKeyStates();
133 void sendChangedKeyStates();
134
135 UIMachineWindow* isItListenedWindow(QObject *pWatchedObject) const;
136 UIMachineView* isItListenedView(QObject *pWatchedObject) const;
137
138 /* Machine logic parent: */
139 UIMachineLogic *m_pMachineLogic;
140
141 /* Registered machine-window(s): */
142 QMap<ulong, UIMachineWindow*> m_windows;
143 /* Registered machine-view(s): */
144 QMap<ulong, UIMachineView*> m_views;
145
146 /* Other keyboard variables: */
147 int m_iKeyboardCaptureViewIndex;
148 const VBoxGlobalSettings &m_globalSettings;
149
150 uint8_t m_pressedKeys[128];
151 uint8_t m_pressedKeysCopy[128];
152
153 QMap<int, uint8_t> m_pressedHostComboKeys;
154
155 bool m_fIsKeyboardCaptured : 1;
156 bool m_bIsHostComboPressed : 1;
157 bool m_bIsHostComboAlone : 1;
158 bool m_fPassCAD : 1;
159
160#if defined(Q_WS_WIN)
161 /* Currently this is used in winLowKeyboardEvent() only: */
162 bool m_bIsHostkeyInCapture;
163 /* Keyboard hook required to capture keyboard event under windows. */
164 static UIKeyboardHandler *m_spKeyboardHandler;
165 HHOOK m_keyboardHook;
166 int m_iKeyboardHookViewIndex;
167#elif defined(Q_WS_MAC)
168 /* The current modifier key mask. Used to figure out which modifier
169 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
170 UInt32 m_darwinKeyModifiers;
171 bool m_fKeyboardGrabbed;
172 int m_iKeyboardGrabViewIndex;
173#endif
174};
175
176#endif // !___UIKeyboardHandler_h___
177
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use