From f8b9b98345ea4add317d31c1ebb92d56b9a70bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 8 Oct 2013 09:57:53 +0200 Subject: [PATCH] [decorations] Allow decorations to use a QWindow instead of QWidget A setMainWindow() method is added which behaves similar to setMainWidget(). In addition a few convenient methods are added which can be used by KWin core to show/hide the decoration without caring whether the decoration uses a QWindow or QWidget. --- libkdecorations/kdecoration.cpp | 35 +++++++++++++++++++++++++++++++++ libkdecorations/kdecoration.h | 23 ++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/libkdecorations/kdecoration.cpp b/libkdecorations/kdecoration.cpp index c633125219..8758f7e92d 100644 --- a/libkdecorations/kdecoration.cpp +++ b/libkdecorations/kdecoration.cpp @@ -109,11 +109,46 @@ void KDecoration::setMainWidget(QWidget* w) widget()->resize(geometry().size()); } +void KDecoration::setMainWindow(QWindow *window) +{ + assert(d->window.isNull()); + d->window.reset(window); + d->window->resize(geometry().size()); +} + Qt::WindowFlags KDecoration::initialWFlags() const { return d->bridge->initialWFlags(); } +void KDecoration::show() +{ + if (!d->w.isNull()) { + d->w->show(); + } else if (!d->window.isNull()) { + d->window->show(); + } +} + +void KDecoration::hide() +{ + if (!d->w.isNull()) { + d->w->hide(); + } else if (!d->window.isNull()) { + d->window->hide(); + } +} + +QRect KDecoration::rect() const +{ + if (!d->w.isNull()) { + return d->w->rect(); + } else if (!d->window.isNull()) { + return QRect(QPoint(0, 0), d->window->size()); + } + return QRect(); +} + bool KDecoration::isActive() const { return d->bridge->isActive(); diff --git a/libkdecorations/kdecoration.h b/libkdecorations/kdecoration.h index 4576312378..7884efb4e5 100644 --- a/libkdecorations/kdecoration.h +++ b/libkdecorations/kdecoration.h @@ -982,6 +982,17 @@ public: * like WX11BypassWM or WStyle_NoBorder are forbidden. */ void createMainWidget(Qt::WindowFlags flags = 0); + /** + * This should be the first function called in init() to specify + * the main window of the decoration. The window should be created + * with window flags specified by initialWFlags(). + * + * This class takes over ownership of the QWindow. + * + * A window decoration can either be QWidget based or QWindow based. If it + * calls both setMainWidget() and setMainWindow() the behavior is undefined. + */ + void setMainWindow(QWindow *window); /** * The flags that should be used when creating the main widget. * It is possible to add more flags when creating the main widget, but only flags @@ -1022,6 +1033,18 @@ public: * a button press was for window tab dragging or for displaying the client menu. */ WindowOperation buttonToWindowOperation(Qt::MouseButtons button); + /** + * Convenient method to show the decoration's widget or window. + **/ + void show(); + /** + * Convenient method to hide the decoration's widget or window. + **/ + void hide(); + /** + * Convenient method to get the geometry of the decoration widget or window. + **/ + QRect rect() const; // Window tabbing