move the windows thumbnail code in WindowEffects, still to be decided if
windowsizes(geometries?) will be in KWindowsystem svn path=/trunk/KDE/kdelibs/; revision=1033125
This commit is contained in:
parent
189618d2e4
commit
660082707f
@ -28,6 +28,7 @@
|
|||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
#include <plasma/framesvg.h>
|
#include <plasma/framesvg.h>
|
||||||
|
#include <plasma/windoweffects.h>
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
@ -38,27 +39,6 @@
|
|||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
|
|
||||||
bool WindowPreview::previewsAvailable() // static
|
|
||||||
{
|
|
||||||
if (!KWindowSystem::compositingActive()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
// hackish way to find out if KWin has the effect enabled,
|
|
||||||
// TODO provide proper support
|
|
||||||
Display *dpy = QX11Info::display();
|
|
||||||
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
|
||||||
int cnt;
|
|
||||||
Atom *list = XListProperties(dpy, DefaultRootWindow(dpy), &cnt);
|
|
||||||
if (list != NULL) {
|
|
||||||
bool ret = (qFind(list, list + cnt, atom) != list + cnt);
|
|
||||||
XFree(list);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowPreview::WindowPreview(QWidget *parent)
|
WindowPreview::WindowPreview(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
@ -69,7 +49,7 @@ WindowPreview::WindowPreview(QWidget *parent)
|
|||||||
|
|
||||||
void WindowPreview::setWindowIds(const QList<WId> wids)
|
void WindowPreview::setWindowIds(const QList<WId> wids)
|
||||||
{
|
{
|
||||||
if (!previewsAvailable()) {
|
if (!WindowEffects::isEffectAvailable(WindowEffects::WindowPreview)) {
|
||||||
setMinimumSize(0,0);
|
setMinimumSize(0,0);
|
||||||
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||||
ids.clear();
|
ids.clear();
|
||||||
@ -83,7 +63,7 @@ void WindowPreview::setWindowIds(const QList<WId> wids)
|
|||||||
ids = wids.mid(0, 4);
|
ids = wids.mid(0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
readWindowSizes();
|
windowSizes = WindowEffects::windowSizes(ids);
|
||||||
QSize s(sizeHint());
|
QSize s(sizeHint());
|
||||||
if (s.isValid()) {
|
if (s.isValid()) {
|
||||||
setFixedSize(sizeHint());
|
setFixedSize(sizeHint());
|
||||||
@ -102,7 +82,7 @@ QSize WindowPreview::sizeHint() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!windowSizes.size() == 0) {
|
if (!windowSizes.size() == 0) {
|
||||||
readWindowSizes();
|
windowSizes = WindowEffects::windowSizes(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxHeight = 0;
|
int maxHeight = 0;
|
||||||
@ -126,22 +106,6 @@ QSize WindowPreview::sizeHint() const
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowPreview::readWindowSizes() const
|
|
||||||
{
|
|
||||||
windowSizes.clear();
|
|
||||||
foreach (WId id, ids) {
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
if (id > 0) {
|
|
||||||
KWindowInfo info = KWindowSystem::windowInfo(id, NET::WMGeometry|NET::WMFrameExtents);
|
|
||||||
windowSizes.append(info.frameGeometry().size());
|
|
||||||
} else {
|
|
||||||
windowSizes.append(QSize());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
windowSizes.append(QSize());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WindowPreview::isEmpty() const
|
bool WindowPreview::isEmpty() const
|
||||||
{
|
{
|
||||||
@ -156,20 +120,17 @@ bool WindowPreview::isEmpty() const
|
|||||||
|
|
||||||
void WindowPreview::setInfo()
|
void WindowPreview::setInfo()
|
||||||
{
|
{
|
||||||
#ifdef Q_WS_X11
|
|
||||||
Display *dpy = QX11Info::display();
|
|
||||||
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
WindowEffects::showWindowThumbnails(parentWidget()->winId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (windowSizes.size() == 0) {
|
if (windowSizes.size() == 0) {
|
||||||
readWindowSizes();
|
windowSizes = WindowEffects::windowSizes(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (windowSizes.size() == 0) {
|
if (windowSizes.size() == 0) {
|
||||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
WindowEffects::showWindowThumbnails(parentWidget()->winId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,30 +156,13 @@ void WindowPreview::setInfo()
|
|||||||
x += s.width() + WINDOW_MARGIN;
|
x += s.width() + WINDOW_MARGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVarLengthArray<long, 1024> data(1 + (6 * numWindows));
|
WindowEffects::showWindowThumbnails(parentWidget()->winId(), ids, m_thumbnailRects);
|
||||||
data[0] = numWindows;
|
|
||||||
|
|
||||||
for (int i = 0; i < numWindows; ++i) {
|
|
||||||
const int start = (i * 6) + 1;
|
|
||||||
const QRect thumbnailRect = m_thumbnailRects[i];
|
|
||||||
|
|
||||||
data[start] = 5;
|
|
||||||
data[start+1] = ids[i];
|
|
||||||
data[start+2] = thumbnailRect.x();
|
|
||||||
data[start+3] = thumbnailRect.y();
|
|
||||||
data[start+4] = thumbnailRect.width();
|
|
||||||
data[start+5] = thumbnailRect.height();
|
|
||||||
}
|
|
||||||
|
|
||||||
XChangeProperty(dpy, parentWidget()->winId(), atom, atom, 32, PropModeReplace,
|
|
||||||
reinterpret_cast<unsigned char *>(data.data()), data.size());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowPreview::paintEvent(QPaintEvent *e)
|
void WindowPreview::paintEvent(QPaintEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e)
|
Q_UNUSED(e)
|
||||||
#ifdef Q_WS_X11
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
qreal left, top, right, bottom;
|
qreal left, top, right, bottom;
|
||||||
@ -229,7 +173,7 @@ void WindowPreview::paintEvent(QPaintEvent *e)
|
|||||||
m_background->resizeFrame(r.size()+QSize(left+right, top+bottom));
|
m_background->resizeFrame(r.size()+QSize(left+right, top+bottom));
|
||||||
m_background->paintFrame(&painter, r.topLeft()-pos()-QPoint(left,top));
|
m_background->paintFrame(&painter, r.topLeft()-pos()-QPoint(left,top));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowPreview::mousePressEvent(QMouseEvent *event)
|
void WindowPreview::mousePressEvent(QMouseEvent *event)
|
||||||
|
@ -58,7 +58,6 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readWindowSizes() const;
|
|
||||||
|
|
||||||
QList<WId> ids;
|
QList<WId> ids;
|
||||||
mutable QList<QSize> windowSizes;
|
mutable QList<QSize> windowSizes;
|
||||||
|
@ -34,6 +34,41 @@ namespace Plasma
|
|||||||
namespace WindowEffects
|
namespace WindowEffects
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//FIXME: check if this works for any atom?
|
||||||
|
bool isEffectAvailable(Effect effect)
|
||||||
|
{
|
||||||
|
if (!KWindowSystem::compositingActive()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
QString effectName;
|
||||||
|
|
||||||
|
switch (effect) {
|
||||||
|
case Slide:
|
||||||
|
effectName = "_KDE_SLIDE";
|
||||||
|
break;
|
||||||
|
case WindowPreview:
|
||||||
|
effectName = "_KDE_WINDOW_PREVIEW";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hackish way to find out if KWin has the effect enabled,
|
||||||
|
// TODO provide proper support
|
||||||
|
Display *dpy = QX11Info::display();
|
||||||
|
Atom atom = XInternAtom(dpy, effectName.toLatin1(), False);
|
||||||
|
int cnt;
|
||||||
|
Atom *list = XListProperties(dpy, DefaultRootWindow(dpy), &cnt);
|
||||||
|
if (list != NULL) {
|
||||||
|
bool ret = (qFind(list, list + cnt, atom) != list + cnt);
|
||||||
|
XFree(list);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void slideWindow(WId id, Plasma::Location location, int offset)
|
void slideWindow(WId id, Plasma::Location location, int offset)
|
||||||
{
|
{
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
@ -104,6 +139,65 @@ void slideWindow(QWidget *widget, Plasma::Location location)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QSize> windowSizes(const QList<WId> &ids)
|
||||||
|
{
|
||||||
|
QList<QSize> windowSizes;
|
||||||
|
foreach (WId id, ids) {
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
if (id > 0) {
|
||||||
|
KWindowInfo info = KWindowSystem::windowInfo(id, NET::WMGeometry|NET::WMFrameExtents);
|
||||||
|
windowSizes.append(info.frameGeometry().size());
|
||||||
|
} else {
|
||||||
|
windowSizes.append(QSize());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
windowSizes.append(QSize());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return windowSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void showWindowThumbnails(WId parent, const QList<WId> &windows, const QList<QRect> &rects)
|
||||||
|
{
|
||||||
|
if (windows.size() != rects.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
Display *dpy = QX11Info::display();
|
||||||
|
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
||||||
|
if (windows.isEmpty()) {
|
||||||
|
XDeleteProperty(dpy, parent, atom);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int numWindows = windows.size();
|
||||||
|
|
||||||
|
QVarLengthArray<long, 1024> data(1 + (6 * numWindows));
|
||||||
|
data[0] = numWindows;
|
||||||
|
|
||||||
|
QList<WId>::const_iterator windowsIt;
|
||||||
|
QList<QRect>::const_iterator rectsIt = rects.constBegin();
|
||||||
|
int i = 0;
|
||||||
|
for (windowsIt = windows.constBegin(); windowsIt != windows.constEnd(); ++windowsIt) {
|
||||||
|
|
||||||
|
const int start = (i * 6) + 1;
|
||||||
|
const QRect thumbnailRect = (*rectsIt);
|
||||||
|
|
||||||
|
data[start] = 5;
|
||||||
|
data[start+1] = (*windowsIt);
|
||||||
|
data[start+2] = thumbnailRect.x();
|
||||||
|
data[start+3] = thumbnailRect.y();
|
||||||
|
data[start+4] = thumbnailRect.width();
|
||||||
|
data[start+5] = thumbnailRect.height();
|
||||||
|
++rectsIt;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
XChangeProperty(dpy, parent, atom, atom, 32, PropModeReplace,
|
||||||
|
reinterpret_cast<unsigned char *>(data.data()), data.size());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,19 @@ namespace Plasma
|
|||||||
*/
|
*/
|
||||||
namespace WindowEffects
|
namespace WindowEffects
|
||||||
{
|
{
|
||||||
|
enum Effect {
|
||||||
|
Slide = 1,
|
||||||
|
WindowPreview = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if an atom property is available
|
||||||
|
*
|
||||||
|
* @param effect the effect we want to check
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
PLASMA_EXPORT bool isEffectAvailable(Effect effect);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a window as sliding from screen edge
|
* Mark a window as sliding from screen edge
|
||||||
*
|
*
|
||||||
@ -56,6 +69,27 @@ namespace WindowEffects
|
|||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
PLASMA_EXPORT void slideWindow(QWidget *widget, Plasma::Location location);
|
PLASMA_EXPORT void slideWindow(QWidget *widget, Plasma::Location location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return dimension of all the windows passed as parameter
|
||||||
|
*
|
||||||
|
* @param ids all the windows we want the size
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
PLASMA_EXPORT QList<QSize> windowSizes(const QList<WId> &ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paint inside the window parent the thumbnails of the windows list in
|
||||||
|
* the respective rectangles of the rects list
|
||||||
|
*
|
||||||
|
* @param parent window where we should paint
|
||||||
|
* @param windows windows we want a thumbnail of.
|
||||||
|
* If it is empty any thumbnail will be deleted
|
||||||
|
* @param rects rectangles in parent coordinates where to paint the window thumbnails.
|
||||||
|
* If it is empty any thumbnail will be deleted
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
PLASMA_EXPORT void showWindowThumbnails(WId parent, const QList<WId> &windows = QList<WId>(), const QList<QRect> &rects = QList<QRect>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
Loading…
Reference in New Issue
Block a user