File indexing completed on 2024-05-05 16:19:50

0001 /*
0002     SPDX-FileCopyrightText: 2001 Ellis Whitehead <ellis@kde.org>
0003 
0004     Win32 port:
0005     SPDX-FileCopyrightText: 2004 Jarosław Staniek <staniek@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.1-or-later
0008 */
0009 
0010 #ifndef _KKEYSERVER_X11_H
0011 #define _KKEYSERVER_X11_H
0012 
0013 #include <X11/Xlib.h>
0014 #include <fixx11h.h>
0015 #include <kwindowsystem_export.h>
0016 #include <xcb/xcb.h>
0017 
0018 namespace KKeyServer
0019 {
0020 static const int MODE_SWITCH = 0x2000;
0021 
0022 /**
0023  * Initialises the values to return for the mod*() functions below.
0024  * Called automatically by those functions if not already initialized.
0025  */
0026 KWINDOWSYSTEM_EXPORT bool initializeMods();
0027 
0028 /**
0029  * Returns true if the current keyboard layout supports the Meta key.
0030  * Specifically, whether the Super or Meta keys are assigned to an X modifier.
0031  * @return true if the keyboard has a Meta key
0032  * @see modXMeta()
0033  */
0034 KWINDOWSYSTEM_EXPORT bool keyboardHasMetaKey();
0035 
0036 /**
0037  * Returns the X11 Shift modifier mask/flag.
0038  * @return the X11 Shift modifier mask/flag.
0039  * @see accelModMaskX()
0040  */
0041 KWINDOWSYSTEM_EXPORT uint modXShift();
0042 
0043 /**
0044  * Returns the X11 Lock modifier mask/flag.
0045  * @return the X11 Lock modifier mask/flag.
0046  * @see accelModMaskX()
0047  */
0048 KWINDOWSYSTEM_EXPORT uint modXLock();
0049 
0050 /**
0051  * Returns the X11 Ctrl modifier mask/flag.
0052  * @return the X11 Ctrl modifier mask/flag.
0053  * @see accelModMaskX()
0054  */
0055 KWINDOWSYSTEM_EXPORT uint modXCtrl();
0056 
0057 /**
0058  * Returns the X11 Alt (Mod1) modifier mask/flag.
0059  * @return the X11 Alt (Mod1) modifier mask/flag.
0060  * @see accelModMaskX()
0061  */
0062 KWINDOWSYSTEM_EXPORT uint modXAlt();
0063 
0064 /**
0065  * Returns the X11 Win (Mod3) modifier mask/flag.
0066  * @return the X11 Win (Mod3) modifier mask/flag.
0067  * @see keyboardHasWinKey()
0068  * @see accelModMaskX()
0069  */
0070 KWINDOWSYSTEM_EXPORT uint modXMeta();
0071 
0072 /**
0073  * Returns the X11 NumLock modifier mask/flag.
0074  * @return the X11 NumLock modifier mask/flag.
0075  * @see accelModMaskX()
0076  */
0077 KWINDOWSYSTEM_EXPORT uint modXNumLock();
0078 
0079 /**
0080  * Returns the X11 ScrollLock modifier mask/flag.
0081  * @return the X11 ScrollLock modifier mask/flag.
0082  * @see accelModMaskX()
0083  */
0084 KWINDOWSYSTEM_EXPORT uint modXScrollLock();
0085 
0086 /**
0087  * Returns the X11 Mode_switch modifier mask/flag.
0088  * @return the X11 Mode_switch modifier mask/flag.
0089  * @see accelModMaskX()
0090  */
0091 KWINDOWSYSTEM_EXPORT uint modXModeSwitch();
0092 
0093 /**
0094  * Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and
0095  * Win (if available).
0096  * @see modXShift()
0097  * @see modXLock()
0098  * @see modXCtrl()
0099  * @see modXAlt()
0100  * @see modXNumLock()
0101  * @see modXWin()
0102  * @see modXScrollLock()
0103  */
0104 KWINDOWSYSTEM_EXPORT uint accelModMaskX();
0105 
0106 /**
0107  * Extracts the symbol from the given Qt key and
0108  * converts it to an X11 symbol + modifiers.
0109  * @param keyQt the qt key code
0110  * @param sym if successful, the symbol will be written here
0111  * @return true if successful, false otherwise
0112  */
0113 KWINDOWSYSTEM_EXPORT bool keyQtToSymX(int keyQt, int *sym);
0114 
0115 /**
0116  * Extracts the code from the given Qt key.
0117  * @param keyQt the qt key code
0118  * @param keyCode if successful, the symbol will be written here
0119  * @return true if successful, false otherwise
0120  */
0121 KWINDOWSYSTEM_EXPORT bool keyQtToCodeX(int keyQt, int *keyCode);
0122 
0123 /**
0124  * Extracts the modifiers from the given Qt key and
0125  * converts them in a mask of X11 modifiers.
0126  * @param keyQt the qt key code
0127  * @param mod if successful, the modifiers will be written here
0128  * @return true if successful, false otherwise
0129  */
0130 KWINDOWSYSTEM_EXPORT bool keyQtToModX(int keyQt, uint *mod);
0131 
0132 #if KWINDOWSYSTEM_ENABLE_DEPRECATED_SINCE(5, 38)
0133 /**
0134  * Converts the given symbol to a Qt key code.
0135  * @param sym the symbol
0136  * @param keyQt if successful, the qt key code will be written here
0137  * @return true if successful, false otherwise
0138  * @deprecated since 5.38, use symXModXToKeyQt in order to support numeric keypad keys too
0139  */
0140 KWINDOWSYSTEM_EXPORT
0141 KWINDOWSYSTEM_DEPRECATED_VERSION(5, 38, "Use KKeyServer::symXModXToKeyQt(uint32_t, uint16_t, int *)")
0142 bool symXToKeyQt(uint sym, int *keyQt);
0143 #endif
0144 
0145 /**
0146  * Converts the given symbol and modifier combination to a Qt key code.
0147  * @param keySym the X key symbol
0148  * @param modX the mask of X11 modifiers
0149  * @param keyQt if successful, the qt key code will be written here
0150  * @return true if successful, false otherwise
0151  */
0152 KWINDOWSYSTEM_EXPORT bool symXModXToKeyQt(uint32_t keySym, uint16_t modX, int *keyQt);
0153 
0154 /**
0155  * Converts the mask of ORed X11 modifiers to
0156  * a mask of ORed Qt key code modifiers.
0157  * @param modX the mask of X11 modifiers
0158  * @param modQt the mask of Qt key code modifiers will be written here
0159  *        if successful
0160  * @return true if successful, false otherwise
0161  */
0162 KWINDOWSYSTEM_EXPORT bool modXToQt(uint modX, int *modQt);
0163 
0164 /**
0165  * Converts an X keypress event into a Qt key + modifier code
0166  * @param e the X11 keypress event
0167  * @param keyModQt the Qt keycode and mask of Qt key code modifiers will be written here
0168  *        if successful
0169  * @return true if successful, false otherwise
0170  */
0171 KWINDOWSYSTEM_EXPORT bool xEventToQt(XEvent *e, int *keyModQt);
0172 
0173 /**
0174  * Converts an XCB keypress event into a Qt key + modifier code
0175  * @param e the XCB keypress event
0176  * @param keyModQt the Qt keycode and mask of Qt key code modifiers will be written here
0177  *        if successful
0178  * @return true if successful, false otherwise
0179  */
0180 KWINDOWSYSTEM_EXPORT bool xcbKeyPressEventToQt(xcb_generic_event_t *e, int *keyModQt);
0181 /**
0182  * Overloaded method for convenience.
0183  */
0184 KWINDOWSYSTEM_EXPORT bool xcbKeyPressEventToQt(xcb_key_press_event_t *e, int *keyModQt);
0185 
0186 }
0187 
0188 #endif // !_KKEYSERVER_X11_H