From 84da08d7b7fcda12c85caeb5a10b4903770a6f69 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun-plugins/noatunmadness/madness.cpp | 123 +++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 noatun-plugins/noatunmadness/madness.cpp (limited to 'noatun-plugins/noatunmadness/madness.cpp') diff --git a/noatun-plugins/noatunmadness/madness.cpp b/noatun-plugins/noatunmadness/madness.cpp new file mode 100644 index 0000000..0b0d086 --- /dev/null +++ b/noatun-plugins/noatunmadness/madness.cpp @@ -0,0 +1,123 @@ +/***************************************************************** + +Copyright (c) 2001 Charles Samuels + 2000 Rik Hemsley + +This code is released under the GNU General Public License 2.0, or any +later version, at your option. I mean, you know the drill, just read +RMS's novel that I'm supposed to put at the top of every story. He's insane. +******************************************************************/ + +#include "madness.h" + +#include +#include +#include +#include +#include + +#include + + +extern "C" +{ +Plugin *create_plugin() +{ + return new Madness(); +} +} + +Madness::Madness() + : MonoFFTScope(100), Plugin(), mWm(this) +{ + connect(&mWm, SIGNAL(currentDesktopChanged(int)), SLOT(update())); + connect(&mWm, SIGNAL(windowAdded(WId)), SLOT(update())); + connect(&mWm, SIGNAL(windowRemoved(WId)), SLOT(update())); + connect(&mWm, SIGNAL(strutChanged()), SLOT(update())); + +} + +Madness::~Madness() +{ + QMap::ConstIterator it(mOriginalPositions.begin()); + + for (; it != mOriginalPositions.end(); ++it) + XMoveWindow(qt_xdisplay(), it.key(), (*it).x(), (*it).y()); +} + +void Madness::update() +{ + mWindowList = mWm.windows(); + mWorkArea = mWm.workArea(); + + QValueList::ConstIterator it(mWindowList.begin()); + + for (; it != mWindowList.end(); ++it) + { + QRect area=KWin::info(*it).frameGeometry; + if (!mOriginalPositions.contains(*it)) + mOriginalPositions.insert(*it, area.topLeft()); + } +} + +void Madness::init() +{ + update(); + MonoFFTScope::start(); +} + +void Madness::scopeEvent(float *d, int size) +{ + int delta=0; // in pixels + for (int count=0; count::ConstIterator it(mWindowList.begin()); + + for (; it != mWindowList.end(); ++it) + { + KWin::Info i(KWin::info(*it)); + + if ((NET::Visible != i.mappingState) || + ((NET::Unknown != i.windowType) && + (NET::Normal != i.windowType) && + (NET::Tool != i.windowType) && + (NET::Menu != i.windowType) && + (NET::Dialog != i.windowType)) || (NET::Max & i.state) + || (NET::Shaded & i.state) + || (mWm.currentDesktop() != i.desktop)) + continue; + + QRect area=i.frameGeometry; + float lightness=100000.0/(area.width()*area.height()); + + int x=area.x(); + int y=area.y(); + + + int dx=(int)((delta*lightness*(area.height()/10)/100))*(KApplication::random()%2 ? -1 : 1); + int dy=(int)((delta*lightness*(area.width()/10)/100))*(KApplication::random()%2 ? -1 : 1); + + if (dx < 0 && (x - dx < mWorkArea.left())) + dx = -dx; + + else if (dx > 0 && (x + dx + area.width() > mWorkArea.right())) + dx = -dx; + + if (dy < 0 && (y - dy < mWorkArea.top())) + dy = -dy; + + else if (dy > 0 && (y + dy + area.height() > mWorkArea.bottom())) + dy = -dy; + + + XMoveWindow(qt_xdisplay(), i.win, x + dx, y + dy); + } + +} + +#include "madness.moc" -- cgit v1.2.1