From d6a31bc921fe0ef3ec473dbdd55479acd1ffdc26 Mon Sep 17 00:00:00 2001 From: Lucas Murray Date: Sat, 31 Jan 2009 15:12:14 +0000 Subject: [PATCH] Introducing the highlight window effect. When activated by the X atom all windows are faded out except the one that is being highlighted. It is nowhere near complete but committing it now so that the Plasma developers can start playing around with it. svn path=/trunk/KDE/kdebase/workspace/; revision=919159 --- effects/CMakeLists.txt | 2 + effects/highlightwindow.cpp | 99 +++++++++++++++++++++++++++++++++ effects/highlightwindow.desktop | 16 ++++++ effects/highlightwindow.h | 52 +++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 effects/highlightwindow.cpp create mode 100644 effects/highlightwindow.desktop create mode 100644 effects/highlightwindow.h diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index ed96f501c7..62c4b08d18 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -42,6 +42,7 @@ SET(kwin4_effect_builtins_sources fade.cpp fadedesktop.cpp fallapart.cpp + highlightwindow.cpp login.cpp logout.cpp magiclamp.cpp @@ -67,6 +68,7 @@ install( FILES fade.desktop fadedesktop.desktop fallapart.desktop + highlightwindow.desktop login.desktop logout.desktop magiclamp.desktop diff --git a/effects/highlightwindow.cpp b/effects/highlightwindow.cpp new file mode 100644 index 0000000000..9c419a0be2 --- /dev/null +++ b/effects/highlightwindow.cpp @@ -0,0 +1,99 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2009 Lucas Murray + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, 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 General Public License +along with this program. If not, see . +*********************************************************************/ + +#include "highlightwindow.h" + +#include + +namespace KWin +{ + +KWIN_EFFECT( highlightwindow, HighlightWindowEffect ) + +HighlightWindowEffect::HighlightWindowEffect() + : m_highlightedWindow( NULL ) + , m_monitorWindow( NULL ) + { + m_atom = XInternAtom( display(), "_KDE_WINDOW_HIGHLIGHT", False ); + effects->registerPropertyType( m_atom, true ); + + // Announce support by creating a dummy version on the root window + unsigned char dummy = 0; + XChangeProperty( display(), rootWindow(), m_atom, m_atom, 8, PropModeReplace, &dummy, 1 ); + } + +HighlightWindowEffect::~HighlightWindowEffect() + { + XDeleteProperty( display(), rootWindow(), m_atom ); + effects->registerPropertyType( m_atom, false ); + } + +void HighlightWindowEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ) + { + // If we are highlighting a window set the translucent flag to all others + if( m_highlightedWindow && m_highlightedWindow != w && m_monitorWindow != w && w->isNormalWindow() ) + data.mask |= PAINT_WINDOW_TRANSLUCENT; + effects->prePaintWindow( w, data, time ); + } + +void HighlightWindowEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) + { + if( m_highlightedWindow && m_highlightedWindow != w && m_monitorWindow != w && w->isNormalWindow() ) + data.opacity *= 0.15; // TODO: Fade out + effects->paintWindow( w, mask, region, data ); + } + +void HighlightWindowEffect::windowAdded( EffectWindow* w ) + { + propertyNotify( w, m_atom ); // Check initial value + } + +void HighlightWindowEffect::windowDeleted( EffectWindow* w ) + { + if( m_monitorWindow == w ) + { // The monitoring window was destroyed + m_monitorWindow = NULL; + m_highlightedWindow = NULL; + } + } + +void HighlightWindowEffect::propertyNotify( EffectWindow* w, long a ) + { + if( a != m_atom ) + return; // Not our atom + + QByteArray byteData = w->readProperty( m_atom, m_atom, 32 ); + if( byteData.length() < 1 ) + return; // Invalid length + long* data = reinterpret_cast( byteData.data() ); + + if( !data[0] ) + { // Purposely clearing highlight + m_monitorWindow = NULL; + m_highlightedWindow = NULL; + return; + } + m_monitorWindow = w; + m_highlightedWindow = effects->findWindow( data[0] ); + if( !m_highlightedWindow ) + kDebug(1212) << "Invalid window targetted for highlight. Requested:" << data[0]; + } + +} // namespace diff --git a/effects/highlightwindow.desktop b/effects/highlightwindow.desktop new file mode 100644 index 0000000000..68a51c8769 --- /dev/null +++ b/effects/highlightwindow.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Name=Highlight Window +Icon=preferences-system-windows-effect-highlightwindow +Comment=Highlight the appropriate window when hovering over taskbar entries + +Type=Service +X-KDE-ServiceTypes=KWin/Effect +X-KDE-PluginInfo-Author=Lucas Murray +X-KDE-PluginInfo-Email=lmurray@undefinedfire.com +X-KDE-PluginInfo-Name=kwin4_effect_highlightwindow +X-KDE-PluginInfo-Version=0.1.0 +X-KDE-PluginInfo-Category=Appearance +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/highlightwindow.h b/effects/highlightwindow.h new file mode 100644 index 0000000000..58c11eb86a --- /dev/null +++ b/effects/highlightwindow.h @@ -0,0 +1,52 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2009 Lucas Murray + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, 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 General Public License +along with this program. If not, see . +*********************************************************************/ + +#ifndef KWIN_HIGHLIGHTWINDOW_H +#define KWIN_HIGHLIGHTWINDOW_H + +#include + +namespace KWin +{ + +class HighlightWindowEffect + : public Effect + { + public: + HighlightWindowEffect(); + virtual ~HighlightWindowEffect(); + + virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ); + virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); + + virtual void windowAdded( EffectWindow* w ); + virtual void windowDeleted( EffectWindow* w ); + + virtual void propertyNotify( EffectWindow* w, long atom ); + + private: + long m_atom; + EffectWindow* m_highlightedWindow; + EffectWindow* m_monitorWindow; + }; + +} // namespace + +#endif