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 | #include "x11windowed_backend.h" | ||||
22 | | ||||
23 | #include <NETWM> | ||||
24 | | ||||
25 | #include <QIcon> | ||||
26 | | ||||
27 | namespace KWin | ||||
28 | { | ||||
29 | | ||||
30 | X11WindowedOutput::X11WindowedOutput(X11WindowedBackend *backend) | ||||
31 | : AbstractOutput(backend) | ||||
32 | , m_backend(backend) | ||||
33 | { | ||||
34 | m_window = xcb_generate_id(m_backend->connection()); | ||||
35 | } | ||||
36 | | ||||
37 | X11WindowedOutput::~X11WindowedOutput() | ||||
38 | { | ||||
39 | xcb_unmap_window(m_backend->connection(), m_window); | ||||
40 | xcb_destroy_window(m_backend->connection(), m_window); | ||||
41 | delete m_winInfo; | ||||
42 | xcb_flush(m_backend->connection()); | ||||
43 | } | ||||
44 | | ||||
45 | void X11WindowedOutput::init() | ||||
46 | { | ||||
47 | uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; | ||||
48 | const uint32_t values[] = { | ||||
49 | m_backend->screen()->black_pixel, | ||||
50 | XCB_EVENT_MASK_KEY_PRESS | | ||||
51 | XCB_EVENT_MASK_KEY_RELEASE | | ||||
52 | XCB_EVENT_MASK_BUTTON_PRESS | | ||||
53 | XCB_EVENT_MASK_BUTTON_RELEASE | | ||||
54 | XCB_EVENT_MASK_POINTER_MOTION | | ||||
55 | XCB_EVENT_MASK_ENTER_WINDOW | | ||||
56 | XCB_EVENT_MASK_LEAVE_WINDOW | | ||||
57 | XCB_EVENT_MASK_STRUCTURE_NOTIFY | | ||||
58 | XCB_EVENT_MASK_EXPOSURE | ||||
59 | }; | ||||
60 | xcb_create_window(m_backend->connection(), | ||||
61 | XCB_COPY_FROM_PARENT, | ||||
62 | m_window, | ||||
63 | m_backend->screen()->root, | ||||
64 | 0, 0, | ||||
65 | pixelSize().width(), pixelSize().height(), | ||||
66 | 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, | ||||
67 | mask, values); | ||||
68 | | ||||
69 | m_winInfo = new NETWinInfo(m_backend->connection(), | ||||
70 | m_window, | ||||
71 | m_backend->screen()->root, | ||||
72 | NET::WMWindowType, NET::Properties2()); | ||||
73 | | ||||
74 | m_winInfo->setWindowType(NET::Normal); | ||||
75 | m_winInfo->setPid(QCoreApplication::applicationPid()); | ||||
76 | QIcon windowIcon = QIcon::fromTheme(QStringLiteral("kwin")); | ||||
77 | auto addIcon = [&windowIcon, this] (const QSize &size) { | ||||
78 | if (windowIcon.actualSize(size) != size) { | ||||
79 | return; | ||||
80 | } | ||||
81 | NETIcon icon; | ||||
82 | icon.data = windowIcon.pixmap(size).toImage().bits(); | ||||
83 | icon.size.width = size.width(); | ||||
84 | icon.size.height = size.height(); | ||||
85 | m_winInfo->setIcon(icon, false); | ||||
86 | }; | ||||
87 | addIcon(QSize(16, 16)); | ||||
88 | addIcon(QSize(32, 32)); | ||||
89 | addIcon(QSize(48, 48)); | ||||
90 | | ||||
91 | | ||||
92 | xcb_map_window(m_backend->connection(), m_window); | ||||
93 | } | ||||
94 | | ||||
95 | QSize X11WindowedOutput::pixelSize() const | ||||
96 | { | ||||
97 | return m_pixelSize; | ||||
98 | } | ||||
99 | | ||||
100 | void X11WindowedOutput::setGeometry(const QPoint &logicalPosition, const QSize &pixelSize) | ||||
101 | { | ||||
102 | m_pixelSize = pixelSize; | ||||
103 | setRawPhysicalSize(pixelSize); | ||||
104 | setGlobalPos(logicalPosition); | ||||
105 | } | ||||
106 | | ||||
107 | void X11WindowedOutput::setWindowTitle(const QString &title) | ||||
108 | { | ||||
109 | m_winInfo->setName(title.toUtf8().constData()); | ||||
110 | } | ||||
111 | | ||||
112 | QPoint X11WindowedOutput::internalPosition() const | ||||
113 | { | ||||
114 | return geometry().topLeft(); | ||||
115 | } | ||||
116 | | ||||
117 | void X11WindowedOutput::setHostPosition(const QPoint &pos) | ||||
118 | { | ||||
119 | m_hostPosition = pos; | ||||
120 | } | ||||
121 | | ||||
122 | } |