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 <plasma/framesvg.h>
|
||||
#include <plasma/windoweffects.h>
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <QX11Info>
|
||||
@ -38,27 +39,6 @@
|
||||
|
||||
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)
|
||||
: QWidget(parent)
|
||||
{
|
||||
@ -69,7 +49,7 @@ WindowPreview::WindowPreview(QWidget *parent)
|
||||
|
||||
void WindowPreview::setWindowIds(const QList<WId> wids)
|
||||
{
|
||||
if (!previewsAvailable()) {
|
||||
if (!WindowEffects::isEffectAvailable(WindowEffects::WindowPreview)) {
|
||||
setMinimumSize(0,0);
|
||||
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
ids.clear();
|
||||
@ -83,7 +63,7 @@ void WindowPreview::setWindowIds(const QList<WId> wids)
|
||||
ids = wids.mid(0, 4);
|
||||
}
|
||||
|
||||
readWindowSizes();
|
||||
windowSizes = WindowEffects::windowSizes(ids);
|
||||
QSize s(sizeHint());
|
||||
if (s.isValid()) {
|
||||
setFixedSize(sizeHint());
|
||||
@ -102,7 +82,7 @@ QSize WindowPreview::sizeHint() const
|
||||
}
|
||||
|
||||
if (!windowSizes.size() == 0) {
|
||||
readWindowSizes();
|
||||
windowSizes = WindowEffects::windowSizes(ids);
|
||||
}
|
||||
|
||||
int maxHeight = 0;
|
||||
@ -126,22 +106,6 @@ QSize WindowPreview::sizeHint() const
|
||||
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
|
||||
{
|
||||
@ -156,20 +120,17 @@ bool WindowPreview::isEmpty() const
|
||||
|
||||
void WindowPreview::setInfo()
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
Display *dpy = QX11Info::display();
|
||||
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
||||
if (isEmpty()) {
|
||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
||||
WindowEffects::showWindowThumbnails(parentWidget()->winId());
|
||||
return;
|
||||
}
|
||||
|
||||
if (windowSizes.size() == 0) {
|
||||
readWindowSizes();
|
||||
windowSizes = WindowEffects::windowSizes(ids);
|
||||
}
|
||||
|
||||
if (windowSizes.size() == 0) {
|
||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
||||
WindowEffects::showWindowThumbnails(parentWidget()->winId());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -195,30 +156,13 @@ void WindowPreview::setInfo()
|
||||
x += s.width() + WINDOW_MARGIN;
|
||||
}
|
||||
|
||||
QVarLengthArray<long, 1024> data(1 + (6 * numWindows));
|
||||
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
|
||||
WindowEffects::showWindowThumbnails(parentWidget()->winId(), ids, m_thumbnailRects);
|
||||
}
|
||||
|
||||
void WindowPreview::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
#ifdef Q_WS_X11
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
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->paintFrame(&painter, r.topLeft()-pos()-QPoint(left,top));
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void WindowPreview::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -58,7 +58,6 @@ protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
void readWindowSizes() const;
|
||||
|
||||
QList<WId> ids;
|
||||
mutable QList<QSize> windowSizes;
|
||||
|
@ -34,6 +34,41 @@ namespace Plasma
|
||||
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)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
@ -104,6 +139,65 @@ void slideWindow(QWidget *widget, Plasma::Location location)
|
||||
#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
|
||||
{
|
||||
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
|
||||
*
|
||||
@ -56,6 +69,27 @@ namespace WindowEffects
|
||||
* @since 4.4
|
||||
*/
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user