2013-06-17 07:35:45 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#ifndef KWIN_WAYLAND_BACKEND_H
|
|
|
|
#define KWIN_WAYLAND_BACKEND_H
|
2013-06-17 08:28:31 +00:00
|
|
|
// KWin
|
|
|
|
#include <kwinglobals.h>
|
2013-06-17 07:35:45 +00:00
|
|
|
// Qt
|
2013-07-03 09:56:05 +00:00
|
|
|
#include <QDir>
|
2013-06-17 07:35:45 +00:00
|
|
|
#include <QHash>
|
2013-06-18 09:48:23 +00:00
|
|
|
#include <QImage>
|
2013-06-17 07:35:45 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QSize>
|
|
|
|
// wayland
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
|
|
|
class QTemporaryFile;
|
|
|
|
class QImage;
|
2013-06-27 07:58:04 +00:00
|
|
|
struct wl_cursor_theme;
|
2013-06-17 07:35:45 +00:00
|
|
|
struct wl_buffer;
|
|
|
|
struct wl_shm;
|
2014-08-13 10:54:02 +00:00
|
|
|
struct wl_event_queue;
|
2013-06-17 07:35:45 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Wayland
|
|
|
|
{
|
|
|
|
class ShmPool;
|
|
|
|
class WaylandBackend;
|
2013-06-27 06:25:59 +00:00
|
|
|
class WaylandSeat;
|
2014-08-13 10:54:02 +00:00
|
|
|
class ConnectionThread;
|
2014-08-18 12:05:35 +00:00
|
|
|
class Registry;
|
2013-06-17 07:35:45 +00:00
|
|
|
|
|
|
|
class CursorData
|
|
|
|
{
|
|
|
|
public:
|
2013-06-18 09:48:23 +00:00
|
|
|
CursorData();
|
2013-06-17 07:35:45 +00:00
|
|
|
~CursorData();
|
|
|
|
bool isValid() const;
|
|
|
|
const QPoint &hotSpot() const;
|
2013-06-18 09:48:23 +00:00
|
|
|
const QImage &cursor() const;
|
2013-06-17 07:35:45 +00:00
|
|
|
private:
|
2013-06-18 09:48:23 +00:00
|
|
|
bool init();
|
|
|
|
QImage m_cursor;
|
2013-06-17 07:35:45 +00:00
|
|
|
QPoint m_hotSpot;
|
|
|
|
bool m_valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
class X11CursorTracker : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-06-27 06:25:59 +00:00
|
|
|
explicit X11CursorTracker(WaylandSeat *seat, WaylandBackend *backend, QObject* parent = 0);
|
2013-06-17 07:35:45 +00:00
|
|
|
virtual ~X11CursorTracker();
|
|
|
|
void resetCursor();
|
|
|
|
private Q_SLOTS:
|
|
|
|
void cursorChanged(uint32_t serial);
|
|
|
|
private:
|
|
|
|
void installCursor(const CursorData &cursor);
|
2013-06-27 06:25:59 +00:00
|
|
|
WaylandSeat *m_seat;
|
2013-06-17 07:35:45 +00:00
|
|
|
QHash<uint32_t, CursorData> m_cursors;
|
|
|
|
WaylandBackend *m_backend;
|
|
|
|
uint32_t m_installedCursor;
|
|
|
|
uint32_t m_lastX11Cursor;
|
|
|
|
};
|
|
|
|
|
2013-06-18 09:48:23 +00:00
|
|
|
class Buffer
|
|
|
|
{
|
|
|
|
public:
|
2013-06-20 06:30:31 +00:00
|
|
|
Buffer(wl_buffer *buffer, const QSize &size, int32_t stride, size_t offset);
|
2013-06-18 09:48:23 +00:00
|
|
|
~Buffer();
|
|
|
|
void copy(const void *src);
|
|
|
|
void setReleased(bool released);
|
2013-06-21 09:31:53 +00:00
|
|
|
void setUsed(bool used);
|
2013-06-18 09:48:23 +00:00
|
|
|
|
|
|
|
wl_buffer *buffer() const;
|
|
|
|
const QSize &size() const;
|
|
|
|
int32_t stride() const;
|
|
|
|
bool isReleased() const;
|
2013-06-21 09:31:53 +00:00
|
|
|
bool isUsed() const;
|
|
|
|
uchar *address();
|
2013-06-18 09:48:23 +00:00
|
|
|
private:
|
|
|
|
wl_buffer *m_nativeBuffer;
|
|
|
|
bool m_released;
|
|
|
|
QSize m_size;
|
|
|
|
int32_t m_stride;
|
2013-06-20 06:30:31 +00:00
|
|
|
size_t m_offset;
|
2013-06-21 09:31:53 +00:00
|
|
|
bool m_used;
|
2013-06-18 09:48:23 +00:00
|
|
|
};
|
|
|
|
|
2013-06-21 09:31:53 +00:00
|
|
|
class ShmPool : public QObject
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
2013-06-21 09:31:53 +00:00
|
|
|
Q_OBJECT
|
2013-06-17 07:35:45 +00:00
|
|
|
public:
|
|
|
|
ShmPool(wl_shm *shm);
|
|
|
|
~ShmPool();
|
|
|
|
bool isValid() const;
|
|
|
|
wl_buffer *createBuffer(const QImage &image);
|
2013-06-18 09:48:23 +00:00
|
|
|
wl_buffer *createBuffer(const QSize &size, int32_t stride, const void *src);
|
2013-06-20 06:30:31 +00:00
|
|
|
void *poolAddress() const;
|
2013-06-21 09:31:53 +00:00
|
|
|
Buffer *getBuffer(const QSize &size, int32_t stride);
|
2013-06-27 07:58:04 +00:00
|
|
|
wl_shm *shm();
|
2013-06-21 09:31:53 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void poolResized();
|
2013-06-17 07:35:45 +00:00
|
|
|
private:
|
|
|
|
bool createPool();
|
2013-06-20 06:30:31 +00:00
|
|
|
bool resizePool(int32_t newSize);
|
2013-06-17 07:35:45 +00:00
|
|
|
wl_shm *m_shm;
|
|
|
|
wl_shm_pool *m_pool;
|
|
|
|
void *m_poolData;
|
2013-06-20 06:30:31 +00:00
|
|
|
int32_t m_size;
|
2013-06-17 07:35:45 +00:00
|
|
|
QScopedPointer<QTemporaryFile> m_tmpFile;
|
|
|
|
bool m_valid;
|
|
|
|
int m_offset;
|
2013-06-18 09:48:23 +00:00
|
|
|
QList<Buffer*> m_buffers;
|
2013-06-17 07:35:45 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 07:58:04 +00:00
|
|
|
class WaylandSeat : public QObject
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
2013-06-27 07:58:04 +00:00
|
|
|
Q_OBJECT
|
2013-06-17 07:35:45 +00:00
|
|
|
public:
|
|
|
|
WaylandSeat(wl_seat *seat, WaylandBackend *backend);
|
|
|
|
virtual ~WaylandSeat();
|
|
|
|
|
|
|
|
void changed(uint32_t capabilities);
|
|
|
|
wl_seat *seat();
|
|
|
|
void pointerEntered(uint32_t serial);
|
|
|
|
void resetCursor();
|
2013-06-27 06:25:59 +00:00
|
|
|
void installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotspot);
|
2013-06-27 07:58:04 +00:00
|
|
|
void installCursorImage(Qt::CursorShape shape);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void loadTheme();
|
2013-06-17 07:35:45 +00:00
|
|
|
private:
|
|
|
|
void destroyPointer();
|
|
|
|
void destroyKeyboard();
|
2013-06-27 07:58:04 +00:00
|
|
|
void destroyTheme();
|
2013-06-17 07:35:45 +00:00
|
|
|
wl_seat *m_seat;
|
|
|
|
wl_pointer *m_pointer;
|
|
|
|
wl_keyboard *m_keyboard;
|
2013-06-27 06:25:59 +00:00
|
|
|
wl_surface *m_cursor;
|
2013-06-27 07:58:04 +00:00
|
|
|
wl_cursor_theme *m_theme;
|
2013-06-27 06:25:59 +00:00
|
|
|
uint32_t m_enteredSerial;
|
2013-06-17 07:35:45 +00:00
|
|
|
QScopedPointer<X11CursorTracker> m_cursorTracker;
|
|
|
|
WaylandBackend *m_backend;
|
|
|
|
};
|
|
|
|
|
2013-07-05 09:11:25 +00:00
|
|
|
class Output : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
Output(wl_output *output, QObject *parent);
|
|
|
|
virtual ~Output();
|
|
|
|
|
|
|
|
wl_output *output();
|
|
|
|
const QSize &physicalSize() const;
|
|
|
|
const QPoint &globalPosition() const;
|
|
|
|
const QString &manufacturer() const;
|
|
|
|
const QString &model() const;
|
|
|
|
const QSize &pixelSize() const;
|
|
|
|
QRect geometry() const;
|
|
|
|
int refreshRate() const;
|
|
|
|
|
|
|
|
void setPhysicalSize(const QSize &size);
|
|
|
|
void setGlobalPosition(const QPoint &pos);
|
|
|
|
void setManufacturer(const QString &manufacturer);
|
|
|
|
void setModel(const QString &model);
|
|
|
|
void setPixelSize(const QSize &size);
|
|
|
|
void setRefreshRate(int refreshRate);
|
|
|
|
|
|
|
|
void emitChanged();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
private:
|
|
|
|
wl_output *m_output;
|
|
|
|
QSize m_physicalSize;
|
|
|
|
QPoint m_globalPosition;
|
|
|
|
QString m_manufacturer;
|
|
|
|
QString m_model;
|
|
|
|
QSize m_pixelSize;
|
|
|
|
int m_refreshRate;
|
|
|
|
};
|
|
|
|
|
2013-06-17 07:35:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Class encapsulating all Wayland data structures needed by the Egl backend.
|
|
|
|
*
|
2014-08-11 22:16:26 +00:00
|
|
|
* It creates the connection to the Wayland Compositor, sets up the registry and creates
|
|
|
|
* the Wayland surface and its shell mapping.
|
2013-06-17 07:35:45 +00:00
|
|
|
*/
|
2014-08-12 07:45:43 +00:00
|
|
|
class KWIN_EXPORT WaylandBackend : public QObject
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
virtual ~WaylandBackend();
|
|
|
|
wl_display *display();
|
|
|
|
wl_registry *registry();
|
|
|
|
void setCompositor(wl_compositor *c);
|
|
|
|
wl_compositor *compositor();
|
|
|
|
void setShell(wl_shell *s);
|
|
|
|
wl_shell *shell();
|
2013-07-05 09:11:25 +00:00
|
|
|
void addOutput(wl_output *o);
|
|
|
|
const QList<Output*> &outputs() const;
|
2013-06-17 07:35:45 +00:00
|
|
|
ShmPool *shmPool();
|
|
|
|
void createSeat(uint32_t name);
|
|
|
|
void createShm(uint32_t name);
|
|
|
|
void ping(uint32_t serial);
|
|
|
|
|
|
|
|
wl_surface *surface() const;
|
|
|
|
const QSize &shellSurfaceSize() const;
|
|
|
|
void setShellSurfaceSize(const QSize &size);
|
2013-06-27 07:58:04 +00:00
|
|
|
void installCursorImage(Qt::CursorShape shape);
|
2013-06-17 07:35:45 +00:00
|
|
|
|
|
|
|
void dispatchEvents();
|
|
|
|
Q_SIGNALS:
|
|
|
|
void shellSurfaceSizeChanged(const QSize &size);
|
2013-07-03 09:56:05 +00:00
|
|
|
void systemCompositorDied();
|
|
|
|
void backendReady();
|
2013-07-05 09:11:25 +00:00
|
|
|
void outputsChanged();
|
2014-08-13 10:54:02 +00:00
|
|
|
void connectionFailed();
|
2013-06-17 07:35:45 +00:00
|
|
|
private:
|
2013-07-03 09:56:05 +00:00
|
|
|
void initConnection();
|
2013-06-17 07:35:45 +00:00
|
|
|
void createSurface();
|
2013-07-05 09:11:25 +00:00
|
|
|
void destroyOutputs();
|
2013-06-17 07:35:45 +00:00
|
|
|
wl_display *m_display;
|
2014-08-13 10:54:02 +00:00
|
|
|
wl_event_queue *m_eventQueue;
|
2014-08-18 12:05:35 +00:00
|
|
|
Registry *m_registry;
|
2013-06-17 07:35:45 +00:00
|
|
|
wl_compositor *m_compositor;
|
|
|
|
wl_shell *m_shell;
|
|
|
|
wl_surface *m_surface;
|
|
|
|
wl_shell_surface *m_shellSurface;
|
|
|
|
QSize m_shellSurfaceSize;
|
|
|
|
QScopedPointer<WaylandSeat> m_seat;
|
|
|
|
QScopedPointer<ShmPool> m_shm;
|
2013-07-05 09:11:25 +00:00
|
|
|
QList<Output*> m_outputs;
|
2014-08-13 10:54:02 +00:00
|
|
|
ConnectionThread *m_connectionThreadObject;
|
|
|
|
QThread *m_connectionThread;
|
2013-06-17 08:28:31 +00:00
|
|
|
|
|
|
|
KWIN_SINGLETON(WaylandBackend)
|
2013-06-17 07:35:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool CursorData::isValid() const
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QPoint& CursorData::hotSpot() const
|
|
|
|
{
|
|
|
|
return m_hotSpot;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2013-06-18 09:48:23 +00:00
|
|
|
const QImage &CursorData::cursor() const
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
|
|
|
return m_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
wl_seat *WaylandSeat::seat()
|
|
|
|
{
|
|
|
|
return m_seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool ShmPool::isValid() const
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
2013-06-20 06:30:31 +00:00
|
|
|
inline
|
|
|
|
void* ShmPool::poolAddress() const
|
|
|
|
{
|
|
|
|
return m_poolData;
|
|
|
|
}
|
|
|
|
|
2013-06-27 07:58:04 +00:00
|
|
|
inline
|
|
|
|
wl_shm *ShmPool::shm()
|
|
|
|
{
|
|
|
|
return m_shm;
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:11:25 +00:00
|
|
|
inline
|
|
|
|
QRect Output::geometry() const
|
|
|
|
{
|
|
|
|
return QRect(m_globalPosition, m_pixelSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QPoint &Output::globalPosition() const
|
|
|
|
{
|
|
|
|
return m_globalPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QString &Output::manufacturer() const
|
|
|
|
{
|
|
|
|
return m_manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QString &Output::model() const
|
|
|
|
{
|
|
|
|
return m_model;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
wl_output *Output::output()
|
|
|
|
{
|
|
|
|
return m_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QSize &Output::physicalSize() const
|
|
|
|
{
|
|
|
|
return m_physicalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QSize &Output::pixelSize() const
|
|
|
|
{
|
|
|
|
return m_pixelSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int Output::refreshRate() const
|
|
|
|
{
|
|
|
|
return m_refreshRate;
|
|
|
|
}
|
|
|
|
|
2013-06-17 07:35:45 +00:00
|
|
|
inline
|
|
|
|
wl_display *WaylandBackend::display()
|
|
|
|
{
|
|
|
|
return m_display;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void WaylandBackend::setCompositor(wl_compositor *c)
|
|
|
|
{
|
|
|
|
m_compositor = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
wl_compositor *WaylandBackend::compositor()
|
|
|
|
{
|
|
|
|
return m_compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
wl_shell *WaylandBackend::shell()
|
|
|
|
{
|
|
|
|
return m_shell;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ShmPool* WaylandBackend::shmPool()
|
|
|
|
{
|
|
|
|
return m_shm.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
wl_surface *WaylandBackend::surface() const
|
|
|
|
{
|
|
|
|
return m_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QSize &WaylandBackend::shellSurfaceSize() const
|
|
|
|
{
|
|
|
|
return m_shellSurfaceSize;
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:11:25 +00:00
|
|
|
inline
|
|
|
|
const QList< Output* >& WaylandBackend::outputs() const
|
|
|
|
{
|
|
|
|
return m_outputs;
|
|
|
|
}
|
|
|
|
|
2013-06-18 09:48:23 +00:00
|
|
|
inline
|
|
|
|
wl_buffer* Buffer::buffer() const
|
|
|
|
{
|
|
|
|
return m_nativeBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
const QSize& Buffer::size() const
|
|
|
|
{
|
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int32_t Buffer::stride() const
|
|
|
|
{
|
|
|
|
return m_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool Buffer::isReleased() const
|
|
|
|
{
|
|
|
|
return m_released;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void Buffer::setReleased(bool released)
|
|
|
|
{
|
|
|
|
m_released = released;
|
|
|
|
}
|
|
|
|
|
2013-06-21 09:31:53 +00:00
|
|
|
inline
|
|
|
|
bool Buffer::isUsed() const
|
|
|
|
{
|
|
|
|
return m_used;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void Buffer::setUsed(bool used)
|
|
|
|
{
|
|
|
|
m_used = used;
|
|
|
|
}
|
|
|
|
|
2013-06-17 07:35:45 +00:00
|
|
|
} // namespace Wayland
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#endif // KWIN_WAYLAND_BACKEND_H
|