KWin
Loading...
Searching...
No Matches
x11_standalone_effects.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
6 SPDX-FileCopyrightText: 2010, 2011, 2017 Martin Gräßlin <mgraesslin@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
11#include "cursor.h"
12#include "screenedge.h"
13#include "utils/common.h"
14#include "workspace.h"
19
20namespace KWin
21{
22
24 : EffectsHandler(compositor, scene)
25{
26 connect(this, &EffectsHandler::virtualScreenGeometryChanged, this, [this]() {
27 if (m_mouseInterceptionWindow.isValid()) {
28 m_mouseInterceptionWindow.setGeometry(virtualScreenGeometry());
29 }
30 });
31}
32
34{
35 // EffectsHandler tries to unload all effects when it's destroyed.
36 // The routine that unloads effects makes some calls (indirectly) to
37 // doUngrabKeyboard and doStopMouseInterception, which are virtual.
38 // Given that any call to a virtual function in the destructor of a base
39 // class will never go to a derived class, we have to unload effects
40 // here. Yeah, this is quite a bit ugly but it's fine; someday, X11
41 // will be dead (or not?).
43}
44
46{
47 auto keyboard = static_cast<X11StandaloneBackend *>(kwinApp()->outputBackend())->keyboard();
48 if (!keyboard->xkbKeymap()) {
49 return false;
50 }
51 bool ret = grabXKeyboard();
52 if (!ret) {
53 return false;
54 }
55 m_x11KeyboardInterception = std::make_unique<EffectsKeyboardInterceptionX11Filter>(this, keyboard);
56 return ret;
57}
58
60{
62 m_x11KeyboardInterception.reset();
63}
64
66{
67 // NOTE: it is intended to not perform an XPointerGrab on X11. See documentation in kwineffects.h
68 // The mouse grab is implemented by using a full screen input only window
69 if (!m_mouseInterceptionWindow.isValid()) {
70 const QSize &s = workspace()->geometry().size();
71 const QRect geo(0, 0, s.width(), s.height());
72 const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
73 const uint32_t values[] = {
74 true,
75 XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION};
76 m_mouseInterceptionWindow.reset(Xcb::createInputWindow(geo, mask, values));
77 defineCursor(shape);
78 } else {
79 defineCursor(shape);
80 }
81 m_mouseInterceptionWindow.map();
82 m_mouseInterceptionWindow.raise();
83 m_x11MouseInterception = std::make_unique<EffectsMouseInterceptionX11Filter>(m_mouseInterceptionWindow, this);
84 // Raise electric border windows above the input windows
85 // so they can still be triggered.
87}
88
90{
91 m_mouseInterceptionWindow.unmap();
92 m_x11MouseInterception.reset();
94}
95
96void EffectsHandlerX11::defineCursor(Qt::CursorShape shape)
97{
98 const xcb_cursor_t c = Cursors::self()->mouse()->x11Cursor(shape);
99 if (c != XCB_CURSOR_NONE) {
100 m_mouseInterceptionWindow.defineCursor(c);
101 }
102}
103
105{
106 m_mouseInterceptionWindow.raise();
107 // Raise electric border windows above the input windows
108 // so they can still be triggered. TODO: Do both at once.
110}
111
112}
113
114#include "moc_x11_standalone_effects.cpp"
xcb_cursor_t x11Cursor(CursorShape shape)
Definition cursor.cpp:225
static Cursors * self()
Definition cursor.cpp:35
Cursor * mouse() const
Definition cursor.h:266
Manager class that handles all the effects.
void virtualScreenGeometryChanged()
EffectsHandlerX11(Compositor *compositor, WorkspaceScene *scene)
void doStartMouseInterception(Qt::CursorShape shape) override
void defineCursor(Qt::CursorShape shape) override
ScreenEdges * screenEdges() const
void stackScreenEdgesUnderOverrideRedirect()
Definition layers.cpp:127
static Workspace * self()
Definition workspace.h:91
QRect geometry() const
void defineCursor(xcb_cursor_t cursor)
Definition xcbutils.h:1890
void reset(xcb_window_t window=XCB_WINDOW_NONE, bool destroy=true)
Definition xcbutils.h:1741
bool isValid() const
Definition xcbutils.h:1710
Workspace * workspace()
Definition workspace.h:830
void KWIN_EXPORT ungrabXKeyboard()
Definition common.cpp:121
bool KWIN_EXPORT grabXKeyboard(xcb_window_t w=XCB_WINDOW_NONE)
Definition common.cpp:90