11#include <QtGui/QImageReader>
14#include <wayland-cursor.h>
22std::unique_ptr<QWaylandCursorTheme> QWaylandCursorTheme::create(QWaylandShm *shm,
int size,
const QString &
themeName)
25 struct ::wl_cursor_theme *theme = wl_cursor_theme_load(nameBytes.
constData(),
size, shm->object());
32 return std::unique_ptr<QWaylandCursorTheme>{
new QWaylandCursorTheme(theme)};
35QWaylandCursorTheme::~QWaylandCursorTheme()
37 wl_cursor_theme_destroy(m_theme);
40wl_cursor *QWaylandCursorTheme::requestCursor(WaylandCursor shape)
42 if (
struct wl_cursor *
cursor = m_cursors[shape])
48 } cursorNamesMap[] = {
60 {
WaitCursor,
"0426c94ea35c87780ff01dc239897213"},
122 {
BusyCursor,
"00000000000000020006000e7e9ffc3f"},
123 {
BusyCursor,
"08e8e1c95fe2fc01f976f1e063a24ccd"},
143 {ResizeNorthCursor,
"n-resize"},
144 {ResizeNorthCursor,
"top_side"},
146 {ResizeSouthCursor,
"s-resize"},
147 {ResizeSouthCursor,
"bottom_side"},
149 {ResizeEastCursor,
"e-resize"},
150 {ResizeEastCursor,
"right_side"},
152 {ResizeWestCursor,
"w-resize"},
153 {ResizeWestCursor,
"left_side"},
155 {ResizeNorthWestCursor,
"nw-resize"},
156 {ResizeNorthWestCursor,
"top_left_corner"},
158 {ResizeSouthEastCursor,
"se-resize"},
159 {ResizeSouthEastCursor,
"bottom_right_corner"},
161 {ResizeNorthEastCursor,
"ne-resize"},
162 {ResizeNorthEastCursor,
"top_right_corner"},
164 {ResizeSouthWestCursor,
"sw-resize"},
165 {ResizeSouthWestCursor,
"bottom_left_corner"},
168 const auto byShape = [](ShapeAndName lhs, ShapeAndName rhs) {
169 return lhs.shape < rhs.shape;
171 Q_ASSERT(std::is_sorted(std::begin(cursorNamesMap), std::end(cursorNamesMap), byShape));
172 const auto p = std::equal_range(std::begin(cursorNamesMap), std::end(cursorNamesMap),
173 ShapeAndName{shape,
""}, byShape);
174 for (
auto it =
p.first;
it !=
p.second; ++
it) {
175 if (wl_cursor *
cursor = wl_cursor_theme_get_cursor(m_theme,
it->name)) {
176 m_cursors[shape] =
cursor;
182 if (shape != ArrowCursor)
183 return requestCursor(ArrowCursor);
191 struct wl_cursor *waylandCursor =
nullptr;
194 waylandCursor = requestCursor(WaylandCursor(shape));
196 qCWarning(lcQpaWayland) <<
"cannot create a wl_cursor_image for a CursorShape";
202 if (!waylandCursor) {
203 qCWarning(lcQpaWayland) <<
"Could not find cursor for shape" << shape;
207 return waylandCursor;
210QWaylandCursorShape::QWaylandCursorShape(::wp_cursor_shape_device_v1 *
object)
214QWaylandCursorShape::~QWaylandCursorShape()
221 using QtWayland::wp_cursor_shape_device_v1;
223 switch (cursorShape) {
231 return wp_cursor_shape_device_v1::shape_default;
233 return wp_cursor_shape_device_v1::shape_ns_resize;
235 return wp_cursor_shape_device_v1::shape_n_resize;
237 return wp_cursor_shape_device_v1::shape_ew_resize;
239 return wp_cursor_shape_device_v1::shape_crosshair;
241 return wp_cursor_shape_device_v1::shape_nesw_resize;
243 return wp_cursor_shape_device_v1::shape_text;
245 return wp_cursor_shape_device_v1::shape_nwse_resize;
247 return wp_cursor_shape_device_v1::shape_progress;
249 return wp_cursor_shape_device_v1::shape_all_scroll;
251 return wp_cursor_shape_device_v1::shape_wait;
253 return wp_cursor_shape_device_v1::shape_row_resize;
255 return wp_cursor_shape_device_v1::shape_not_allowed;
257 return wp_cursor_shape_device_v1::shape_col_resize;
259 return wp_cursor_shape_device_v1::shape_pointer;
261 return wp_cursor_shape_device_v1::shape_grab;
263 return wp_cursor_shape_device_v1::shape_help;
265 return wp_cursor_shape_device_v1::shape_grabbing;
271 return wp_cursor_shape_device_v1::shape_grab;
273 return wp_cursor_shape_device_v1::shape_default;
276void QWaylandCursorShape::setShape(uint32_t serial,
Qt::CursorShape shape)
278 set_shape(serial, qtCursorShapeToWaylandShape(shape));
281QWaylandCursor::QWaylandCursor(QWaylandDisplay *
display)
292 if (!
display->shm()->formatSupported(
img.format())) {
305 memcpy(
buffer->image()->bits(),
img.bits(),
size_t(
img.sizeInBytes()));
315 bitmapBuffer = cursorBitmapBuffer(mDisplay,
cursor);
317 int fallbackOutputScale = int(
window->devicePixelRatio());
318 const auto seats = mDisplay->inputDevices();
319 for (
auto *seat : seats)
325 mLastPos =
event.globalPosition().toPoint();
328QPoint QWaylandCursor::pos()
const
333void QWaylandCursor::setPos(
const QPoint &
pos)
336 qCWarning(lcQpaWayland) <<
"Setting cursor position is not possible on wayland";
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
The QCursor class provides a mouse cursor with an arbitrary shape.
QBitmap bitmap() const
Returns the cursor bitmap, or a null bitmap if it is one of the standard cursors.
QPixmap pixmap() const
Returns the cursor pixmap.
Qt::CursorShape shape() const
Returns the cursor shape identifier.
QBitmap mask() const
Returns the cursor bitmap mask, or a null bitmap if it is one of the standard cursors.
void convertTo(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QImage toImage() const
Converts the pixmap to a QImage.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLocal8Bit() const &
QSet< QString >::iterator it
struct wl_display * display
Combined button and popup list for selecting options.
static QtWayland::wp_cursor_shape_device_v1::shape qtCursorShapeToWaylandShape(Qt::CursorShape cursorShape)
#define qCWarning(category,...)
static QString themeName()
GLenum GLuint GLintptr GLsizeiptr size
[1]
item setCursor(Qt::IBeamCursor)
[1]