From bac5a278698e4be0b5a813dfa103cebdb5c7d8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 25 Jun 2009 14:41:45 +0000 Subject: [PATCH] Resize effect: paints a rubber band on top of the window while resizing illustrating the geometry to change. It requires some more adjustments so that the rubber band is also shown when window content is not shown during resize. svn path=/trunk/KDE/kdebase/workspace/; revision=987091 --- effects/CMakeLists.txt | 1 + effects/resize/CMakeLists.txt | 15 ++++ effects/resize/resize.cpp | 126 ++++++++++++++++++++++++++++++++++ effects/resize/resize.desktop | 17 +++++ effects/resize/resize.h | 47 +++++++++++++ 5 files changed, 206 insertions(+) create mode 100644 effects/resize/CMakeLists.txt create mode 100644 effects/resize/resize.cpp create mode 100644 effects/resize/resize.desktop create mode 100644 effects/resize/resize.h diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 58ebcd577d..b12ca6c988 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -64,6 +64,7 @@ include( magiclamp/CMakeLists.txt ) include( translucency/CMakeLists.txt ) include( minimizeanimation/CMakeLists.txt ) include( presentwindows/CMakeLists.txt ) +include( resize/CMakeLists.txt ) include( scalein/CMakeLists.txt ) include( shadow/CMakeLists.txt ) include( showfps/CMakeLists.txt ) diff --git a/effects/resize/CMakeLists.txt b/effects/resize/CMakeLists.txt new file mode 100644 index 0000000000..f59fce3bac --- /dev/null +++ b/effects/resize/CMakeLists.txt @@ -0,0 +1,15 @@ +####################################### +# Effect + +# Source files +set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} + resize/resize.cpp + ) + +# .desktop files +install( FILES + resize/resize.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) + +####################################### +# Config diff --git a/effects/resize/resize.cpp b/effects/resize/resize.cpp new file mode 100644 index 0000000000..711918073e --- /dev/null +++ b/effects/resize/resize.cpp @@ -0,0 +1,126 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2009 Martin Gräßlin + +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 "resize.h" + +#ifdef KWIN_HAVE_OPENGL_COMPOSITING +#include +#endif +#ifdef KWIN_HAVE_XRENDER_COMPOSITING +#include +#include +#endif + +#include + +namespace KWin +{ + +KWIN_EFFECT( resize, ResizeEffect ) + +ResizeEffect::ResizeEffect() + : m_active( false ) + , m_resizeWindow( 0 ) + { + reconfigure( ReconfigureAll ); + } + +ResizeEffect::~ResizeEffect() + { + } + +void ResizeEffect::prePaintScreen( ScreenPrePaintData& data, int time ) + { + if( m_active ) + { + data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + } + effects->prePaintScreen( data, time ); + } + +void ResizeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) + { + effects->paintWindow( w, mask, region, data ); + if( m_active && w == m_resizeWindow ) + { + QRegion intersection = m_originalWindowRect.intersected( w->geometry() ); + QRegion paintRegion = m_originalWindowRect.united( w->geometry() ).subtracted( intersection ); + float alpha = 0.8f; + QColor color = KColorScheme( QPalette::Normal, KColorScheme::Selection ).background().color(); + +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + if( effects->compositingType() == OpenGLCompositing) + { + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glColor4f( color.red() / 255.0f, color.green() / 255.0f, color.blue() / 255.0f, alpha ); + glBegin( GL_QUADS ); + foreach( const QRect &r, paintRegion.rects() ) + { + glVertex2i( r.x(), r.y() ); + glVertex2i( r.x() + r.width(), r.y() ); + glVertex2i( r.x() + r.width(), r.y() + r.height() ); + glVertex2i( r.x(), r.y() + r.height() ); + } + glEnd(); + glPopAttrib(); + } +#endif + +#ifdef KWIN_HAVE_XRENDER_COMPOSITING + if( effects->compositingType() == XRenderCompositing) + { + XRenderColor col; + col.alpha = int( alpha * 0xffff ); + col.red = int( alpha * 0xffff * color.red() / 255 ); + col.green = int( alpha * 0xffff * color.green() / 255 ); + col.blue= int( alpha * 0xffff * color.blue() / 255 ); + foreach( const QRect &r, paintRegion.rects() ) + XRenderFillRectangle( display(), PictOpOver, effects->xrenderBufferPicture(), + &col, r.x(), r.y(), r.width(), r.height()); + } +#endif + } + } + +void ResizeEffect::windowUserMovedResized( EffectWindow* w, bool first, bool last ) + { + if( first && last ) + { + // not interested in maximized + return; + } + if( first && w->isUserResize() && !w->isUserMove() ) + { + m_active = true; + m_resizeWindow = w; + m_originalWindowRect = w->geometry(); + w->addRepaintFull(); + } + if( m_active && w == m_resizeWindow && last ) + { + m_active = false; + m_resizeWindow = NULL; + effects->addRepaintFull(); + } + } + +} // namespace diff --git a/effects/resize/resize.desktop b/effects/resize/resize.desktop new file mode 100644 index 0000000000..607775a3ff --- /dev/null +++ b/effects/resize/resize.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Resize Window +Icon=preferences-system-windows-effect-resize +Comment=Effect to outline geometry while resizing a window + +Type=Service +X-KDE-ServiceTypes=KWin/Effect +X-KDE-PluginInfo-Author=Martin Gräßlin +X-KDE-PluginInfo-Email=kde@martin-graesslin.com +X-KDE-PluginInfo-Name=kwin4_effect_resize +X-KDE-PluginInfo-Version=0.1.0 +X-KDE-PluginInfo-Category=Window Management +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +X-KDE-Library=kwin4_effect_builtins +X-KDE-Ordering=60 diff --git a/effects/resize/resize.h b/effects/resize/resize.h new file mode 100644 index 0000000000..4e2057ad46 --- /dev/null +++ b/effects/resize/resize.h @@ -0,0 +1,47 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2009 Martin Gräßlin + +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_RESIZE_H +#define KWIN_RESIZE_H + +#include + +namespace KWin +{ + +class ResizeEffect + : public Effect + { + public: + ResizeEffect(); + ~ResizeEffect(); + virtual void prePaintScreen( ScreenPrePaintData& data, int time ); + virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); + virtual void windowUserMovedResized( EffectWindow *w, bool first, bool last ); + + private: + bool m_active; + EffectWindow* m_resizeWindow; + QRegion m_originalWindowRect; + }; + +} + +#endif