1/*
2 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3 SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
4*/
5
6#include "keyboardgrabber_p.h"
7
8#include <QWindow>
9
10KeyboardGrabber::KeyboardGrabber(QWindow *window)
11 : ShortcutInhibition()
12 , m_grabbedWindow(window)
13 , m_grabbingKeyboard(false)
14{
15}
16
17KeyboardGrabber::~KeyboardGrabber()
18{
19 disableInhibition();
20}
21
22void KeyboardGrabber::enableInhibition()
23{
24 if (m_grabbingKeyboard || !m_grabbedWindow) {
25 return;
26 }
27 m_grabbingKeyboard = m_grabbedWindow->setKeyboardGrabEnabled(true);
28}
29
30void KeyboardGrabber::disableInhibition()
31{
32 if (!m_grabbingKeyboard) {
33 return;
34 }
35 m_grabbingKeyboard = !(m_grabbedWindow->setKeyboardGrabEnabled(false));
36}
37
38bool KeyboardGrabber::shortcutsAreInhibited() const
39{
40 return m_grabbingKeyboard;
41}
42

source code of kguiaddons/src/recorder/keyboardgrabber.cpp