KGlobalAccel

kglobalaccel_win.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "kglobalaccel_win.h"
9 
10 #include "kkeyserver_win.h"
11 
12 #include <QWidgetList>
13 #ifdef Q_OS_WIN
14 
15 #include "globalshortcutsregistry.h"
16 #include "kglobalaccel.h"
17 #include "logging_p.h"
18 
19 #include <QDebug>
20 
21 #include <windows.h>
22 
23 KGlobalAccelImpl::KGlobalAccelImpl(GlobalShortcutsRegistry *owner)
24  : m_owner(owner)
25  , m_enabled(false)
26 {
27 }
28 
29 bool KGlobalAccelImpl::grabKey(int keyQt, bool grab)
30 {
31  if (!keyQt) {
32  qCWarning(KGLOBALACCELD) << "Tried to grab key with null code.";
33  return false;
34  }
35 
36  uint keyCodeW;
37  uint keyModW;
38  KKeyServer::keyQtToCodeWin(keyQt, &keyCodeW);
39  KKeyServer::keyQtToModWin(keyQt, &keyModW);
40 
41  ATOM id = GlobalAddAtom(MAKEINTATOM(keyQt));
42  bool b;
43  if (grab) {
44  b = RegisterHotKey(reinterpret_cast<HWND>(winId()), id, keyModW, keyCodeW);
45  } else {
46  b = UnregisterHotKey(reinterpret_cast<HWND>(winId()), id);
47  }
48 
49  return b;
50 }
51 
52 void KGlobalAccelImpl::setEnabled(bool enable)
53 {
54  m_enabled = enable;
55 }
56 
57 bool KGlobalAccelImpl::winEvent(MSG *message, long *result)
58 {
59  if (message->message == WM_HOTKEY) {
60  uint keyCodeW = HIWORD(message->lParam);
61  uint keyModW = LOWORD(message->lParam);
62 
63  int keyCodeQt, keyModQt;
64  KKeyServer::codeWinToKeyQt(keyCodeW, &keyCodeQt);
65  KKeyServer::modWinToKeyQt(keyModW, &keyModQt);
66 
67  return m_owner->keyPressed(keyCodeQt | keyModQt);
68  }
69  return false;
70 }
71 
72 #endif // Q_OS_WIN
void setEnabled(bool)
Enable/disable all shortcuts. There will not be any grabbed shortcuts at this point.
bool keyQtToCodeWin(int keyQt, uint *sym)
Global Shortcut Registry.
QPixmap grab(const QRect &rectangle)
WId winId() const const
bool keyQtToModWin(int keyQt, uint *mod)
bool grabKey(int key, bool grab)
This function registers or unregisters a certain key for global capture, depending on grab...
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun May 16 2021 22:53:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.