KWin
Loading...
Searching...
No Matches
x11_standalone_non_composited_outline.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: 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
6 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10// own
12// KWin libs
14// xcb
15#include <xcb/render.h>
16
17namespace KWin
18{
19
21 : OutlineVisual(outline)
22 , m_initialized(false)
23{
24}
25
29
31{
32 if (!m_initialized) {
33 const QRect geo(0, 0, 1, 1);
34 const uint32_t values[] = {true};
35 // TODO: use template variant
36 m_leftOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
37 m_rightOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
38 m_topOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
39 m_bottomOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
40 m_initialized = true;
41 }
42
43 const int defaultDepth = Xcb::defaultDepth();
44
45 const QRect &outlineGeometry = m_outline->geometry();
46 // left/right parts are between top/bottom, they don't reach as far as the corners
47 const uint16_t verticalWidth = 5;
48 const uint16_t verticalHeight = outlineGeometry.height() - 10;
49 const uint16_t horizontalWidth = outlineGeometry.width();
50 const uint horizontalHeight = 5;
51 m_leftOutline.setGeometry(outlineGeometry.x(), outlineGeometry.y() + 5, verticalWidth, verticalHeight);
52 m_rightOutline.setGeometry(outlineGeometry.x() + outlineGeometry.width() - 5, outlineGeometry.y() + 5, verticalWidth, verticalHeight);
53 m_topOutline.setGeometry(outlineGeometry.x(), outlineGeometry.y(), horizontalWidth, horizontalHeight);
54 m_bottomOutline.setGeometry(outlineGeometry.x(), outlineGeometry.y() + outlineGeometry.height() - 5, horizontalWidth, horizontalHeight);
55
56 const xcb_render_color_t white = {0xffff, 0xffff, 0xffff, 0xffff};
57 QColor qGray(Qt::gray);
58 const xcb_render_color_t gray = {
59 uint16_t(0xffff * qGray.redF()),
60 uint16_t(0xffff * qGray.greenF()),
61 uint16_t(0xffff * qGray.blueF()),
62 0xffff};
63 const xcb_render_color_t black = {0, 0, 0, 0xffff};
64 {
65 xcb_pixmap_t xpix = xcb_generate_id(connection());
66 xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), verticalWidth, verticalHeight);
67 XRenderPicture pic(xpix, defaultDepth);
68
69 xcb_rectangle_t rect = {0, 0, 5, verticalHeight};
70 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, white, 1, &rect);
71 rect.x = 1;
72 rect.width = 3;
73 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, gray, 1, &rect);
74 rect.x = 2;
75 rect.width = 1;
76 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, black, 1, &rect);
77
78 m_leftOutline.setBackgroundPixmap(xpix);
79 m_rightOutline.setBackgroundPixmap(xpix);
80 // According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
81 xcb_free_pixmap(connection(), xpix);
82 }
83 {
84 xcb_pixmap_t xpix = xcb_generate_id(connection());
85 xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), horizontalWidth, horizontalHeight);
86 XRenderPicture pic(xpix, defaultDepth);
87
88 xcb_rectangle_t rect = {0, 0, horizontalWidth, horizontalHeight};
89 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, white, 1, &rect);
90 xcb_rectangle_t grayRects[] = {
91 {1, 1, uint16_t(horizontalWidth - 2), 3},
92 {1, 4, 3, 1},
93 {int16_t(horizontalWidth - 4), 4, 3, 1}};
94 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, gray, 3, grayRects);
95 xcb_rectangle_t blackRects[] = {
96 {2, 2, uint16_t(horizontalWidth - 4), 1},
97 {2, 3, 1, 2},
98 {int16_t(horizontalWidth - 3), 3, 1, 2}};
99 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, black, 3, blackRects);
100 m_topOutline.setBackgroundPixmap(xpix);
101 // According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
102 xcb_free_pixmap(connection(), xpix);
103 }
104 {
105 xcb_pixmap_t xpix = xcb_generate_id(connection());
106 xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), outlineGeometry.width(), 5);
107 XRenderPicture pic(xpix, defaultDepth);
108
109 xcb_rectangle_t rect = {0, 0, horizontalWidth, horizontalHeight};
110 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, white, 1, &rect);
111 xcb_rectangle_t grayRects[] = {
112 {1, 1, uint16_t(horizontalWidth - 2), 3},
113 {1, 0, 3, 1},
114 {int16_t(horizontalWidth - 4), 0, 3, 1}};
115 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, gray, 3, grayRects);
116 xcb_rectangle_t blackRects[] = {
117 {2, 2, uint16_t(horizontalWidth - 4), 1},
118 {2, 0, 1, 2},
119 {int16_t(horizontalWidth - 3), 0, 1, 2}};
120 xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, black, 3, blackRects);
121 m_bottomOutline.setBackgroundPixmap(xpix);
122 // According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
123 xcb_free_pixmap(connection(), xpix);
124 }
125 forEachWindow(&Xcb::Window::clear);
126 forEachWindow(&Xcb::Window::map);
127}
128
130{
131 forEachWindow(&Xcb::Window::unmap);
132}
133
134} // namespace
This class is used to show the outline of a given geometry.
Definition outline.h:38
QRect geometry
Definition outline.h:40
Outline *const m_outline
Definition outline.h:130
Wrapper around XRender Picture.
void create(const QRectF &geometry, uint32_t mask=0, const uint32_t *values=nullptr, xcb_window_t parent=rootWindow())
Definition xcbutils.h:1726
void setGeometry(const QRectF &geometry)
Definition xcbutils.h:1748
void setBackgroundPixmap(xcb_pixmap_t pixmap)
Definition xcbutils.h:1881
KWIN_EXPORT xcb_window_t rootWindow()
Definition xcb.h:24
KWIN_EXPORT xcb_connection_t * connection()
Definition xcb.h:19