23#include <kkeyserver.h>
26#include <QApplication>
30Q_LOGGING_CATEGORY(KWIN_CORE,
"kwin_core", QtWarningMsg)
31Q_LOGGING_CATEGORY(KWIN_OPENGL,
"kwin_scene_opengl", QtWarningMsg)
32Q_LOGGING_CATEGORY(KWIN_QPAINTER,
"kwin_scene_qpainter", QtWarningMsg)
33Q_LOGGING_CATEGORY(KWIN_VIRTUALKEYBOARD,
"kwin_virtualkeyboard", QtWarningMsg)
50 : QRect(x, y, width, height)
57 , m_area(other.area())
64 QRect::operator=(other);
65 m_area = other.
area();
70static int server_grab_count = 0;
74 if (++server_grab_count == 1) {
81 Q_ASSERT(server_grab_count > 0);
82 if (--server_grab_count == 0) {
88static bool keyboard_grabbed =
false;
92 if (QWidget::keyboardGrabber() !=
nullptr) {
95 if (keyboard_grabbed) {
96 qCDebug(KWIN_CORE) <<
"Failed to grab X Keyboard: already grabbed by us";
99 if (qApp->activePopupWidget() !=
nullptr) {
100 qCDebug(KWIN_CORE) <<
"Failed to grab X Keyboard: no popup widget";
103 if (w == XCB_WINDOW_NONE) {
106 const xcb_grab_keyboard_cookie_t c = xcb_grab_keyboard_unchecked(
connection(),
false, w,
xTime(),
107 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
110 qCDebug(KWIN_CORE) <<
"Failed to grab X Keyboard: grab null";
113 if (grab->status != XCB_GRAB_STATUS_SUCCESS) {
114 qCDebug(KWIN_CORE) <<
"Failed to grab X Keyboard: grab failed with status" << grab->status;
117 keyboard_grabbed =
true;
123 if (!keyboard_grabbed) {
125 qCDebug(KWIN_CORE) <<
"ungrabXKeyboard() called but keyboard not grabbed!";
127 keyboard_grabbed =
false;
128 xcb_ungrab_keyboard(
connection(), XCB_TIME_CURRENT_TIME);
137 if (button == XCB_BUTTON_INDEX_1) {
138 return Qt::LeftButton;
140 if (button == XCB_BUTTON_INDEX_2) {
141 return Qt::MiddleButton;
143 if (button == XCB_BUTTON_INDEX_3) {
144 return Qt::RightButton;
146 if (button == XCB_BUTTON_INDEX_4) {
149 if (button == XCB_BUTTON_INDEX_5) {
157 Qt::MouseButtons ret = {};
158 if (state & XCB_KEY_BUT_MASK_BUTTON_1) {
159 ret |= Qt::LeftButton;
161 if (state & XCB_KEY_BUT_MASK_BUTTON_2) {
162 ret |= Qt::MiddleButton;
164 if (state & XCB_KEY_BUT_MASK_BUTTON_3) {
165 ret |= Qt::RightButton;
167 if (state & XCB_KEY_BUT_MASK_BUTTON_4) {
170 if (state & XCB_KEY_BUT_MASK_BUTTON_5) {
178 Qt::KeyboardModifiers ret = {};
179 if (state & XCB_KEY_BUT_MASK_SHIFT) {
180 ret |= Qt::ShiftModifier;
182 if (state & XCB_KEY_BUT_MASK_CONTROL) {
183 ret |= Qt::ControlModifier;
185 if (state & KKeyServer::modXAlt()) {
186 ret |= Qt::AltModifier;
188 if (state & KKeyServer::modXMeta()) {
189 ret |= Qt::MetaModifier;
194QPointF
popupOffset(
const QRectF &anchorRect,
const Qt::Edges anchorEdge,
const Qt::Edges gravity,
const QSizeF popupSize)
197 switch (anchorEdge & (Qt::LeftEdge | Qt::RightEdge)) {
199 anchorPoint.setX(anchorRect.x());
202 anchorPoint.setX(anchorRect.x() + anchorRect.width());
205 anchorPoint.setX(qRound(anchorRect.x() + anchorRect.width() / 2.0));
207 switch (anchorEdge & (Qt::TopEdge | Qt::BottomEdge)) {
209 anchorPoint.setY(anchorRect.y());
212 anchorPoint.setY(anchorRect.y() + anchorRect.height());
215 anchorPoint.setY(qRound(anchorRect.y() + anchorRect.height() / 2.0));
221 QPointF popupPosAdjust;
222 switch (gravity & (Qt::LeftEdge | Qt::RightEdge)) {
224 popupPosAdjust.setX(-popupSize.width());
227 popupPosAdjust.setX(0);
230 popupPosAdjust.setX(qRound(-popupSize.width() / 2.0));
232 switch (gravity & (Qt::TopEdge | Qt::BottomEdge)) {
234 popupPosAdjust.setY(-popupSize.height());
237 popupPosAdjust.setY(0);
240 popupPosAdjust.setY(qRound(-popupSize.height() / 2.0));
243 return anchorPoint + popupPosAdjust;
248 QRectF geometry = rect;
252 geometry.moveRight(bounds.right());
253 geometry.moveBottom(bounds.bottom());
257 geometry.moveLeft(bounds.left());
258 geometry.moveBottom(bounds.bottom());
264 geometry.moveLeft(bounds.left());
265 geometry.moveTop(bounds.top());
269 geometry.moveRight(bounds.right());
270 geometry.moveTop(bounds.top());
StrutRect & operator=(const StrutRect &other)
StrutRect(QRect rect=QRect(), StrutArea area=StrutAreaInvalid)
KWIN_EXPORT xcb_window_t rootWindow()
Qt::MouseButtons x11ToQtMouseButtons(int state)
Qt::MouseButton x11ToQtMouseButton(int button)
KWIN_EXPORT xcb_timestamp_t xTime()
QPointF popupOffset(const QRectF &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSizeF popupSize)
QRectF gravitateGeometry(const QRectF &rect, const QRectF &bounds, Gravity gravity)
KWIN_EXPORT xcb_connection_t * connection()
void KWIN_EXPORT ungrabXKeyboard()
void KWIN_EXPORT grabXServer()
Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state)
void KWIN_EXPORT ungrabXServer()
bool KWIN_EXPORT grabXKeyboard(xcb_window_t w=XCB_WINDOW_NONE)
std::unique_ptr< T, CDeleter > UniqueCPtr