From 6a60d6cf75df65b2c9ddec2ddf126ac7ec43590e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 26 Jul 2009 18:58:27 +0000 Subject: [PATCH] WindowEffects namespace: here will go functions used to set atoms on windows to trigger kwin effects, without having t use xlibs directly from the rest of the code svn path=/trunk/KDE/kdelibs/; revision=1002670 --- CMakeLists.txt | 2 ++ dialog.cpp | 84 ++++++++++++++++++++++------------------------- dialog.h | 1 + windoweffects.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++ windoweffects.h | 50 ++++++++++++++++++++++++++++ 5 files changed, 175 insertions(+), 45 deletions(-) create mode 100644 windoweffects.cpp create mode 100644 windoweffects.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c8c6bf70d..cbed57f29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ set(plasma_LIB_SRCS version.cpp view.cpp wallpaper.cpp + windoweffects.cpp widgets/checkbox.cpp widgets/combobox.cpp widgets/flashinglabel.cpp @@ -211,6 +212,7 @@ set(plasma_LIB_INCLUDES extendergroup.h extenderitem.h paintutils.h + windoweffects.h framesvg.h plasma.h plasma_export.h diff --git a/dialog.cpp b/dialog.cpp index e26279090..be29ed194 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -49,6 +49,7 @@ #include "plasma/private/extender_p.h" #include "plasma/framesvg.h" #include "plasma/theme.h" +#include "plasma/windoweffects.h" #ifdef Q_WS_X11 #include @@ -526,6 +527,19 @@ void Dialog::showEvent(QShowEvent * event) emit dialogVisible(true); } +void Dialog::focusInEvent(QFocusEvent *event) +{ + Q_UNUSED(event) + + if (d->view) { + d->view->setFocus(); + } + + if (d->graphicsWidget) { + d->graphicsWidget->setFocus(); + } +} + void Dialog::moveEvent(QMoveEvent *event) { Q_UNUSED(event) @@ -559,37 +573,26 @@ void Dialog::animatedHide(Plasma::Direction direction) return; } -#ifdef Q_WS_X11 - //set again the atom, the location could have changed - QDesktopWidget *desktop = QApplication::desktop(); - QRect avail = desktop->availableGeometry(desktop->screenNumber(pos())); - - Display *dpy = QX11Info::display(); - Atom atom = XInternAtom( dpy, "_KDE_SLIDE", False ); - QVarLengthArray data(2); + Location location = Desktop; switch (direction) { - case Left: - data[0] = avail.left(); - data[1] = 0; - break; - case Up: - data[0] = avail.top(); - data[1] = 1; + case Down: + location = BottomEdge; break; case Right: - data[0] = avail.right(); - data[1] = 2; + location = RightEdge; + break; + case Left: + location = LeftEdge; + break; + case Up: + location = TopEdge; break; - case Down: default: - data[0] = avail.bottom(); - data[1] = 3; + break; } - XChangeProperty(dpy, winId(), atom, atom, 32, PropModeReplace, - reinterpret_cast(data.data()), data.size()); -#endif + Plasma::WindowEffects::setSlidingWindow(winId(), location); hide(); } @@ -601,36 +604,27 @@ void Dialog::animatedShow(Plasma::Direction direction) return; } -#ifdef Q_WS_X11 - QDesktopWidget *desktop = QApplication::desktop(); - QRect avail = desktop->availableGeometry(desktop->screenNumber(pos())); - - Display *dpy = QX11Info::display(); - Atom atom = XInternAtom( dpy, "_KDE_SLIDE", False ); - QVarLengthArray data(2); + //copied to not add new api + Location location = Desktop; switch (direction) { - case Right: - data[0] = avail.left(); - data[1] = 0; - break; - case Down: - data[0] = avail.top(); - data[1] = 1; + case Up: + location = BottomEdge; break; case Left: - data[0] = avail.right(); - data[1] = 2; + location = RightEdge; + break; + case Right: + location = LeftEdge; + break; + case Down: + location = TopEdge; break; - case Up: default: - data[0] = avail.bottom(); - data[1] = 3; + break; } - XChangeProperty(dpy, winId(), atom, atom, 32, PropModeReplace, - reinterpret_cast(data.data()), data.size()); -#endif + Plasma::WindowEffects::setSlidingWindow(winId(), location); show(); diff --git a/dialog.h b/dialog.h index 12cb9789a..e21981539 100644 --- a/dialog.h +++ b/dialog.h @@ -120,6 +120,7 @@ class PLASMA_EXPORT Dialog : public QWidget bool eventFilter(QObject *watched, QEvent *event); void hideEvent(QHideEvent *event); void showEvent(QShowEvent *event); + void focusInEvent(QFocusEvent *event); void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); diff --git a/windoweffects.cpp b/windoweffects.cpp new file mode 100644 index 000000000..4be4300cc --- /dev/null +++ b/windoweffects.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2009 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "windoweffects.h" + +#include + + +namespace Plasma +{ + +namespace WindowEffects +{ + +void setSlidingWindow(WId id, Plasma::Location location) +{ +#ifdef Q_WS_X11 + Display *dpy = QX11Info::display(); + //set again the atom, the location could have changed + QDesktopWidget *desktop = QApplication::desktop(); + + Window dummy; + int x; + int y; + uint width; + uint height; + uint bw; + uint d; + XGetGeometry(dpy, id, &dummy, &x, &y, &width, &height, &bw, &d); + + QRect avail = desktop->availableGeometry(QPoint(x, y));//desktop->screenNumber(pos())); + + Atom atom = XInternAtom( dpy, "_KDE_SLIDE", False ); + QVarLengthArray data(2); + + switch (location) { + case LeftEdge: + data[0] = avail.left(); + data[1] = 0; + break; + case TopEdge: + data[0] = avail.top(); + data[1] = 1; + break; + case RightEdge: + data[0] = avail.right(); + data[1] = 2; + break; + case BottomEdge: + data[0] = avail.bottom(); + data[1] = 3; + default: + break; + } + + if (location == Desktop || location == Floating) { + XDeleteProperty(dpy, id, atom); + } else { + XChangeProperty(dpy, id, atom, atom, 32, PropModeReplace, + reinterpret_cast(data.data()), data.size()); + } +#endif +} + +} + +} diff --git a/windoweffects.h b/windoweffects.h new file mode 100644 index 000000000..64414c425 --- /dev/null +++ b/windoweffects.h @@ -0,0 +1,50 @@ +/* + * Copyright 2009 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef PLASMA_WINDOWEFFECTS_H +#define PLASMA_WINDOWEFFECTS_H + +#include +#include + +#include +#include + +#ifdef Q_WS_X11 +#include +#include +#endif + +/** @headerfile plasma/windoweffect.h */ + +namespace Plasma +{ + +/** + * Namespace for all window effects for Plasma/KWin interaction + */ +namespace WindowEffects +{ + PLASMA_EXPORT void setSlidingWindow(WId id, Plasma::Location location); +} + +} // namespace Plasma + +#endif +