Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/x11/windowed/x11windowed_output.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright 2019 Roman Gilg <subdiff@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #include "x11windowed_output.h" | ||||
21 | | ||||
22 | #include "x11windowed_backend.h" | ||||
23 | | ||||
24 | #include <NETWM> | ||||
25 | | ||||
26 | #if HAVE_X11_XINPUT | ||||
27 | #include <X11/extensions/XInput2.h> | ||||
28 | #endif | ||||
29 | | ||||
30 | #include <QIcon> | ||||
31 | | ||||
32 | namespace KWin | ||||
33 | { | ||||
34 | | ||||
35 | X11WindowedOutput::X11WindowedOutput(X11WindowedBackend *backend) | ||||
36 | : AbstractOutput(backend) | ||||
37 | , m_backend(backend) | ||||
38 | { | ||||
39 | m_window = xcb_generate_id(m_backend->connection()); | ||||
40 | } | ||||
41 | | ||||
42 | X11WindowedOutput::~X11WindowedOutput() | ||||
43 | { | ||||
44 | xcb_unmap_window(m_backend->connection(), m_window); | ||||
45 | xcb_destroy_window(m_backend->connection(), m_window); | ||||
46 | delete m_winInfo; | ||||
47 | xcb_flush(m_backend->connection()); | ||||
48 | } | ||||
49 | | ||||
50 | void X11WindowedOutput::init() | ||||
51 | { | ||||
52 | uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; | ||||
53 | const uint32_t values[] = { | ||||
54 | m_backend->screen()->black_pixel, | ||||
55 | XCB_EVENT_MASK_KEY_PRESS | | ||||
56 | XCB_EVENT_MASK_KEY_RELEASE | | ||||
57 | XCB_EVENT_MASK_BUTTON_PRESS | | ||||
58 | XCB_EVENT_MASK_BUTTON_RELEASE | | ||||
59 | XCB_EVENT_MASK_POINTER_MOTION | | ||||
60 | XCB_EVENT_MASK_ENTER_WINDOW | | ||||
61 | XCB_EVENT_MASK_LEAVE_WINDOW | | ||||
62 | XCB_EVENT_MASK_STRUCTURE_NOTIFY | | ||||
63 | XCB_EVENT_MASK_EXPOSURE | ||||
64 | }; | ||||
65 | xcb_create_window(m_backend->connection(), | ||||
66 | XCB_COPY_FROM_PARENT, | ||||
67 | m_window, | ||||
68 | m_backend->screen()->root, | ||||
69 | 0, 0, | ||||
70 | pixelSize().width(), pixelSize().height(), | ||||
71 | 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, | ||||
72 | mask, values); | ||||
73 | | ||||
74 | // select xinput 2 events | ||||
75 | initXInputForWindow(); | ||||
76 | | ||||
77 | m_winInfo = new NETWinInfo(m_backend->connection(), | ||||
78 | m_window, | ||||
79 | m_backend->screen()->root, | ||||
80 | NET::WMWindowType, NET::Properties2()); | ||||
81 | | ||||
82 | m_winInfo->setWindowType(NET::Normal); | ||||
83 | m_winInfo->setPid(QCoreApplication::applicationPid()); | ||||
84 | QIcon windowIcon = QIcon::fromTheme(QStringLiteral("kwin")); | ||||
85 | auto addIcon = [&windowIcon, this] (const QSize &size) { | ||||
86 | if (windowIcon.actualSize(size) != size) { | ||||
87 | return; | ||||
88 | } | ||||
89 | NETIcon icon; | ||||
90 | icon.data = windowIcon.pixmap(size).toImage().bits(); | ||||
91 | icon.size.width = size.width(); | ||||
92 | icon.size.height = size.height(); | ||||
93 | m_winInfo->setIcon(icon, false); | ||||
94 | }; | ||||
95 | addIcon(QSize(16, 16)); | ||||
96 | addIcon(QSize(32, 32)); | ||||
97 | addIcon(QSize(48, 48)); | ||||
98 | | ||||
99 | xcb_map_window(m_backend->connection(), m_window); | ||||
100 | } | ||||
101 | | ||||
102 | void X11WindowedOutput::initXInputForWindow() | ||||
103 | { | ||||
104 | if (!m_backend->hasXInput()) { | ||||
105 | return; | ||||
106 | } | ||||
107 | #if HAVE_X11_XINPUT | ||||
108 | XIEventMask evmasks[1]; | ||||
109 | unsigned char mask1[XIMaskLen(XI_LASTEVENT)]; | ||||
110 | | ||||
111 | memset(mask1, 0, sizeof(mask1)); | ||||
112 | XISetMask(mask1, XI_TouchBegin); | ||||
113 | XISetMask(mask1, XI_TouchUpdate); | ||||
114 | XISetMask(mask1, XI_TouchOwnership); | ||||
115 | XISetMask(mask1, XI_TouchEnd); | ||||
116 | evmasks[0].deviceid = XIAllMasterDevices; | ||||
117 | evmasks[0].mask_len = sizeof(mask1); | ||||
118 | evmasks[0].mask = mask1; | ||||
119 | XISelectEvents(m_backend->display(), m_window, evmasks, 1); | ||||
120 | #else | ||||
121 | Q_UNUSED(window) | ||||
122 | #endif | ||||
123 | } | ||||
124 | | ||||
125 | QSize X11WindowedOutput::pixelSize() const | ||||
126 | { | ||||
127 | return m_pixelSize; | ||||
128 | } | ||||
129 | | ||||
130 | void X11WindowedOutput::setGeometry(const QPoint &logicalPosition, const QSize &pixelSize) | ||||
131 | { | ||||
132 | m_pixelSize = pixelSize; | ||||
133 | | ||||
134 | // Physicial size must be adjusted, such that QPA calculates correct sizes of | ||||
135 | // internal elements. | ||||
136 | setRawPhysicalSize(pixelSize / 96.0 * 25.4 / scale()); | ||||
137 | | ||||
138 | setGlobalPos(logicalPosition); | ||||
139 | } | ||||
140 | | ||||
141 | void X11WindowedOutput::setWindowTitle(const QString &title) | ||||
142 | { | ||||
143 | m_winInfo->setName(title.toUtf8().constData()); | ||||
144 | } | ||||
145 | | ||||
146 | QPoint X11WindowedOutput::internalPosition() const | ||||
147 | { | ||||
148 | return geometry().topLeft(); | ||||
149 | } | ||||
150 | | ||||
151 | void X11WindowedOutput::setHostPosition(const QPoint &pos) | ||||
152 | { | ||||
153 | m_hostPosition = pos; | ||||
154 | } | ||||
155 | | ||||
156 | } |