KGuiAddons

keyboardgrabber.cpp
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}
QWidget * window(QObject *job)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.