10#include <QtCore/QThread>
11#include <QtCore/QDebug>
12#include <qpa/qwindowsysteminterface.h>
16#if defined(QQNXSCREEN_DEBUG)
17#define qScreenDebug qDebug
19#define qScreenDebug QT_NO_QDEBUG_MACRO
22#if defined(QQNX_PHYSICAL_SCREEN_WIDTH) && QQNX_PHYSICAL_SCREEN_WIDTH > 0 \
23 && defined(QQNX_PHYSICAL_SCREEN_HEIGHT) && QQNX_PHYSICAL_SCREEN_HEIGHT > 0
24#define QQNX_PHYSICAL_SCREEN_SIZE_DEFINED
25#elif defined(QQNX_PHYSICAL_SCREEN_WIDTH) || defined(QQNX_PHYSICAL_SCREEN_HEIGHT)
26#error Please define QQNX_PHYSICAL_SCREEN_WIDTH and QQNX_PHYSICAL_SCREEN_HEIGHT to values greater than zero
38 const int result = screen_get_display_property_iv(
display, SCREEN_PROPERTY_PHYSICAL_SIZE,
val);
41 return QSize(150, 90);
44 if (
val[0] > 0 &&
val[1] > 0)
47 qScreenDebug(
"QQnxScreen: screen_get_display_property_iv() reported an invalid "
48 "physical screen size (%dx%d). Falling back to QQNX_PHYSICAL_SCREEN_SIZE "
49 "environment variable.",
val[0],
val[1]);
51 const QString envPhySizeStr =
qgetenv(
"QQNX_PHYSICAL_SCREEN_SIZE");
54 const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1;
55 const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1;
57 if (envWidth <= 0 || envHeight <= 0) {
58 qWarning(
"QQnxScreen: The value of QQNX_PHYSICAL_SCREEN_SIZE must be in the format "
59 "\"width,height\" in mm, with width, height > 0. Defaulting to 150x90. "
60 "Example: QQNX_PHYSICAL_SCREEN_SIZE=150,90");
61 return QSize(150, 90);
64 return QSize(envWidth, envHeight);
67#if defined(QQNX_PHYSICAL_SCREEN_SIZE_DEFINED)
68 const QSize defSize(QQNX_PHYSICAL_SCREEN_WIDTH, QQNX_PHYSICAL_SCREEN_HEIGHT);
69 qWarning(
"QQnxScreen: QQNX_PHYSICAL_SCREEN_SIZE variable not set. Falling back to defines "
70 "QQNX_PHYSICAL_SCREEN_WIDTH/QQNX_PHYSICAL_SCREEN_HEIGHT (%dx%d)",
75 qWarning(
"QQnxScreen: QQNX_PHYSICAL_SCREEN_SIZE variable not set. "
76 "Could not determine physical screen size. Defaulting to 150x90.");
77 return QSize(150, 90);
82 : m_screenContext(screenContext),
85 m_primaryScreen(primaryScreen),
87 m_nativeOrientation(
Qt::PrimaryOrientation),
93 int result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_ROTATION,
97 m_currentRotation = m_initialRotation;
102 "Failed to query display size");
104 m_currentGeometry = m_initialGeometry =
QRect(0, 0,
val[0],
val[1]);
107 Q_SCREEN_CHECKERROR(screen_get_display_property_cv(m_display, SCREEN_PROPERTY_ID_STRING, 100,
108 name),
"Failed to query display name");
121 m_currentPhysicalSize = m_initialPhysicalSize = screenSize;
123 m_currentPhysicalSize = m_initialPhysicalSize = screenSize.
transposed();
142 qWarning(
"grabWindow: unknown window");
156 qWarning(
"grabWindow: size is null");
162 if (screen_create_context(&
context, SCREEN_DISPLAY_MANAGER_CONTEXT)) {
164 qWarning(
"grabWindow: root privileges required");
166 qWarning(
"grabWindow: cannot create context");
173 screen_get_context_property_iv(
context, SCREEN_PROPERTY_DISPLAY_COUNT, &
count);
175 const size_t idLen = 30;
180 screen_display_t *displays =
static_cast<screen_display_t*
>
181 (calloc(
count,
sizeof(screen_display_t)));
182 screen_get_context_property_pv(
context, SCREEN_PROPERTY_DISPLAYS, (
void **)displays);
183 screen_get_display_property_cv(m_display, SCREEN_PROPERTY_ID_STRING, idLen, matchId);
185 while (
count && !found) {
187 screen_get_display_property_cv(displays[
count], SCREEN_PROPERTY_ID_STRING, idLen,
id);
188 found = !strncmp(
id, matchId, idLen);
206 int val = SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
207 screen_set_pixmap_property_iv(
pixmap, SCREEN_PROPERTY_USAGE, &
val);
208 val = SCREEN_FORMAT_RGBA8888;
209 screen_set_pixmap_property_iv(
pixmap, SCREEN_PROPERTY_FORMAT, &
val);
211 int err = screen_set_pixmap_property_iv(
pixmap, SCREEN_PROPERTY_BUFFER_SIZE,
rect+2);
212 err = err || screen_create_pixmap_buffer(
pixmap);
213 err = err || screen_get_pixmap_property_pv(
pixmap, SCREEN_PROPERTY_RENDER_BUFFERS,
214 reinterpret_cast<void**
>(&
buffer));
215 err = err || screen_get_buffer_property_pv(
buffer, SCREEN_PROPERTY_POINTER, &
pointer);
216 err = err || screen_get_buffer_property_iv(
buffer, SCREEN_PROPERTY_STRIDE, &
stride);
224 qWarning(
"grabWindow: capture error");
226 screen_destroy_pixmap(
pixmap);
228 qWarning(
"grabWindow: display/pixmap error ");
230 screen_destroy_context(
context);
253 return QRect(m_currentGeometry.
x(), m_currentGeometry.
y(),
254 m_currentGeometry.
width(), m_currentGeometry.
height() - m_keyboardHeight);
264 screen_display_mode_t displayMode;
265 int result = screen_get_display_property_pv(m_display, SCREEN_PROPERTY_MODE,
reinterpret_cast<void **
>(&displayMode));
267 if (
result != 0 || displayMode.refresh == 0) {
268 qWarning(
"QQnxScreen: Failed to query screen mode. Using default value of 60Hz");
276 uint(displayMode.width),
uint(displayMode.height),
uint(displayMode.refresh),
uint(displayMode.interlaced));
277 return static_cast<qreal>(displayMode.refresh);
282 return m_nativeOrientation;
290 if (m_currentRotation == 0)
292 else if (m_currentRotation == 90)
294 else if (m_currentRotation == 180)
301 if (m_currentRotation == 0)
303 else if (m_currentRotation == 90)
305 else if (m_currentRotation == 180)
329 return ((angle1 - angle2) % 180) != 0;
346 m_currentGeometry =
QRect(0, 0, m_initialGeometry.
height(), m_initialGeometry.
width());
347 m_currentPhysicalSize =
QSize(m_initialPhysicalSize.
height(), m_initialPhysicalSize.
width());
349 m_currentGeometry =
QRect(0, 0, m_initialGeometry.
width(), m_initialGeometry.
height());
350 m_currentPhysicalSize = m_initialPhysicalSize;
359 resizeWindows(previousScreenGeometry);
372 if (m_primaryScreen) {
379 screen_flush_context( m_screenContext, 0 );
386void QQnxScreen::resizeNativeWidgetWindow(
QQnxWindow *
w,
const QRect &previousScreenGeometry)
const
388 const qreal relativeX =
static_cast<qreal>(
w->geometry().topLeft().x()) / previousScreenGeometry.
width();
389 const qreal relativeY =
static_cast<qreal>(
w->geometry().topLeft().y()) / previousScreenGeometry.
height();
390 const qreal relativeWidth =
static_cast<qreal>(
w->geometry().width()) / previousScreenGeometry.
width();
391 const qreal relativeHeight =
static_cast<qreal>(
w->geometry().height()) / previousScreenGeometry.
height();
396 w->setGeometry(windowGeometry);
402void QQnxScreen::resizeTopLevelWindow(
QQnxWindow *
w,
const QRect &previousScreenGeometry)
const
404 QRect windowGeometry =
w->geometry();
406 const qreal relativeCenterX =
static_cast<qreal>(
w->geometry().center().x()) / previousScreenGeometry.
width();
407 const qreal relativeCenterY =
static_cast<qreal>(
w->geometry().center().y()) / previousScreenGeometry.
height();
415 const int x1 = windowGeometry.
x();
416 const int y1 = windowGeometry.
y();
417 const int x2 =
x1 + windowGeometry.
width();
455 windowGeometry.
setSize(newSize);
457 if (windowGeometry.
x() < 0)
460 if (windowGeometry.
y() < 0)
464 w->setGeometry(windowGeometry);
470void QQnxScreen::resizeWindows(
const QRect &previousScreenGeometry)
481 resizeNativeWidgetWindow(
w, previousScreenGeometry);
484 resizeTopLevelWindow(
w, previousScreenGeometry);
527 if (
window != m_coverWindow) {
529 if (
window == m_rootWindow)
531 if (numWindowsRemoved > 0)
542 if (
window != m_coverWindow) {
552 if (
window != m_coverWindow) {
568 result = screen_get_window_property_iv(
rootWindow()->nativeHandle(), SCREEN_PROPERTY_ZORDER, &topZorder);
571 qWarning(
"QQnxScreen: failed to query root window z-order, errno=%d", errno);
580 int underlayZorder = -1;
582 Q_FOREACH (screen_window_t underlay, m_underlays) {
586 screen_set_window_property_iv(underlay, SCREEN_PROPERTY_ZORDER, &underlayZorder);
592 (*it)->updateZorder(topZorder);
595 Q_FOREACH (screen_window_t overlay, m_overlays) {
597 screen_set_window_property_iv(overlay, SCREEN_PROPERTY_ZORDER, &topZorder);
603 screen_flush_context(m_screenContext, 0);
608 if (!m_primaryScreen)
623void QQnxScreen::keyboardHeightChanged(
int height)
625 if (
height == m_keyboardHeight)
628 m_keyboardHeight =
height;
633void QQnxScreen::addOverlayWindow(screen_window_t
window)
639void QQnxScreen::addUnderlayWindow(screen_window_t
window)
645void QQnxScreen::removeOverlayOrUnderlayWindow(screen_window_t
window)
648 if (numRemoved > 0) {
657 const screen_window_t windowHandle =
reinterpret_cast<screen_window_t
>(
window);
659 if (screen_get_window_property_pv(windowHandle, SCREEN_PROPERTY_DISPLAY, (
void**)&
display) != 0) {
660 qWarning(
"QQnx: Failed to get screen for window, errno=%d", errno);
665 if (screen_get_window_property_iv(windowHandle, SCREEN_PROPERTY_ZORDER, &zorder) != 0) {
666 qWarning(
"QQnx: Failed to get z-order for window, errno=%d", errno);
670 char windowNameBuffer[256] = { 0 };
673 if (screen_get_window_property_cv(windowHandle, SCREEN_PROPERTY_ID_STRING,
674 sizeof(windowNameBuffer) - 1, windowNameBuffer) != 0) {
675 qWarning(
"QQnx: Failed to get id for window, errno=%d", errno);
693 addUnderlayWindow(windowHandle);
695 addOverlayWindow(windowHandle);
703 const screen_window_t windowHandle =
reinterpret_cast<screen_window_t
>(
window);
705 removeOverlayOrUnderlayWindow(windowHandle);
766 if (
ok && disablePowerSave) {
767 const int mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
768 int result = screen_set_window_property_iv(
window->nativeHandle(), SCREEN_PROPERTY_IDLE_MODE, &
mode);
770 qWarning(
"QQnxRootWindow: failed to disable power saving mode");
void push_front(rvalue_ref t)
void push_back(parameter_type t)
const_iterator constBegin() const noexcept
qsizetype removeAll(const AT &t)
reverse_iterator rbegin()
void append(parameter_type t)
const_iterator constEnd() const noexcept
QThread * thread() const
Returns the thread in which the object lives.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
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
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
void windowClosed(void *window)
QQnxScreen(screen_context_t context, screen_display_t display, bool primaryScreen)
Qt::ScreenOrientation nativeOrientation() const override
Reimplement this function in subclass to return the native orientation of the screen,...
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
QPlatformCursor * cursor() const override
Reimplement this function in subclass to return the cursor of the screen.
Qt::ScreenOrientation orientation() const override
Reimplement this function in subclass to return the current orientation of the screen,...
QWindow * topLevelAt(const QPoint &point) const override
Return the given top level window for a given position.
void lowerWindow(QQnxWindow *window)
bool isPrimaryScreen() const
void raiseWindow(QQnxWindow *window)
void activateWindowGroup(const QByteArray &id)
void foreignWindowClosed(void *window)
void removeWindow(QQnxWindow *child)
void addWindow(QQnxWindow *child)
QRect availableGeometry() const override
Reimplement in subclass to return the pixel geometry of the available space This normally is the desk...
screen_context_t nativeContext() const
void deactivateWindowGroup(const QByteArray &id)
QPixmap grabWindow(WId window, int x, int y, int width, int height) const override
This function is called when Qt needs to be able to grab the content of a window.
QQnxWindow * findWindow(screen_window_t windowHandle) const
void foreignWindowCreated(void *window)
void setRootWindow(QQnxWindow *)
int depth() const override
Reimplement in subclass to return current depth of the screen.
screen_display_t nativeDisplay() const
void setRotation(int rotation)
QQnxWindow * rootWindow() const
void newWindowCreated(void *window)
qreal refreshRate() const override
Reimplement this function in subclass to return the vertical refresh rate of the screen,...
void windowGroupStateChanged(const QByteArray &id, Qt::WindowState state)
The QQnxWindow is the base class of the various classes used as instances of QPlatformWindow in the Q...
void setExposed(bool exposed)
void setScreen(QQnxScreen *platformScreen)
void setRotation(int rotation)
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
\inmodule QtCore\reentrant
constexpr void moveCenter(const QPoint &p) noexcept
Moves the rectangle, leaving the center point at the given position.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const
Convenience function to compute the angle of rotation to get from rotation a to rotation b.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
void scale(int w, int h, Qt::AspectRatioMode mode) noexcept
Scales the size to a rectangle with the given width and height, according to the specified mode:
constexpr QSize transposed() const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QThread * currentThread()
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry)
static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation)
static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState=-1)
QSet< QString >::iterator it
struct wl_display * display
Combined button and popup list for selecting options.
@ InvertedLandscapeOrientation
@ InvertedPortraitOrientation
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.
#define Q_FOREACH(variable, container)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLfloat GLfloat GLfloat x1
GLenum GLenum GLsizei count
const void GLsizei GLsizei stride
GLfixed GLfixed GLfixed y2
GLsizei const void * pointer
#define Q_SCREEN_CRITICALERROR(x, message)
#define Q_SCREEN_CHECKERROR(x, message)
static const int MAX_UNDERLAY_ZORDER
static QT_BEGIN_NAMESPACE QSize determineScreenSize(screen_display_t display, bool primaryScreen)
static bool isOrthogonal(int angle1, int angle2)
Check if the supplied angles are perpendicular to each other.
static int defaultDepth()
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
bool contains(const AT &t) const noexcept