diff --git a/CMakeLists.txt b/CMakeLists.txt index 20f21a93fa..3129d86520 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,15 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/effects ) +include(UsePkgConfig) +PKGCONFIG(libcaptury CAPTURY_INCLUDES CAPTURY_LINK_DIR CAPTURY_LDFLAGS CAPTURY_CFLAGS) +if( CAPTURY_LDFLAGS ) + SET( CAPTURY_FOUND TRUE ) +endif( CAPTURY_LDFLAGS ) +macro_bool_to_01( CAPTURY_FOUND HAVE_CAPTURY ) + +configure_file(config-kwin.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kwin.h ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) ########### next target ############### @@ -70,6 +79,13 @@ set(kwin_KDEINIT_SRCS effects/desktopchangeslide.cpp ) +if( CAPTURY_FOUND ) + set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} + effects/videorecord.cpp + ) + include_directories(${CAPTURY_INCLUDES}) +endif( CAPTURY_FOUND ) + if(HAVE_OPENGL) set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} effects/wavywindows.cpp @@ -104,6 +120,10 @@ endif (X11_Xrender_FOUND) if (X11_Xfixes_FOUND) target_link_libraries(kdeinit_kwin ${X11_Xfixes_LIB}) endif (X11_Xfixes_FOUND) +if( HAVE_CAPTURY ) + target_link_libraries(kdeinit_kwin ${CAPTURY_LDFLAGS}) +endif( HAVE_CAPTURY ) + install(TARGETS kdeinit_kwin DESTINATION ${LIB_INSTALL_DIR} ) diff --git a/config-kwin.h.cmake b/config-kwin.h.cmake new file mode 100644 index 0000000000..c1a78976c6 --- /dev/null +++ b/config-kwin.h.cmake @@ -0,0 +1,2 @@ +/* Define if you have libcaptury */ +#cmakedefine HAVE_CAPTURY 1 diff --git a/effects.cpp b/effects.cpp index 7c004feff6..e3c4156221 100644 --- a/effects.cpp +++ b/effects.cpp @@ -28,6 +28,9 @@ License. See the file "COPYING" for the exact licensing terms. #include "effects/shakymove.h" #include "effects/shiftworkspaceup.h" #include "effects/showfps.h" +#ifdef HAVE_CAPTURY +#include "effects/videorecord.h" +#endif #ifdef HAVE_OPENGL #include "effects/wavywindows.h" #endif @@ -128,6 +131,9 @@ EffectsHandler::EffectsHandler() return; KWinInternal::effects = this; +#ifdef HAVE_CAPTURY + registerEffect("VideoRecord", new GenericEffectFactory); +#endif registerEffect("ShowFps", new GenericEffectFactory); registerEffect("Zoom", new GenericEffectFactory); registerEffect("PresentWindows", new GenericEffectFactory); diff --git a/effects/videorecord.cpp b/effects/videorecord.cpp new file mode 100644 index 0000000000..dc0fc7480b --- /dev/null +++ b/effects/videorecord.cpp @@ -0,0 +1,143 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2006 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +/* + + This effect allows recording a video from the session. + + Requires libcaptury: + + - svn co svn://battousai.mylair.de/capseo/trunk + - you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am + - ./autogen.sh + - the usual configure && make && make install procedure + (you may want to pass --enable-theora --with-accel=x86 [or amd64]) + + - svn co svn://battousai.mylair.de/captury/trunk/libcaptury + - you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am + - ./autogen.sh + - the usual configure && make && make install procedure + + Video is saved to /tmp/kwin_video.cps, use + "cpsrecode -i kwin_video.cps -o - | mplayer -" to play, + use mencoder the same way to create a video. + +*/ + +#include + +#include "videorecord.h" + +#include +#include +#include + +#include + +#include + +namespace KWinInternal +{ + +VideoRecordEffect::VideoRecordEffect() + : client( NULL ) + { + KActionCollection* actionCollection = new KActionCollection( this ); + KAction* a = static_cast< KAction* >( actionCollection->addAction( "VideoRecord" )); + a->setText( i18n("Toggle Video Recording" )); + a->setGlobalShortcut( KShortcut( Qt::CTRL + Qt::Key_F11 )); + connect( a, SIGNAL( triggered( bool )), this, SLOT( toggleRecording())); + area = QRect( 0, 0, displayWidth(), displayHeight()); + } + +VideoRecordEffect::~VideoRecordEffect() + { + stopRecording(); + } + +void VideoRecordEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) + { + effects->paintScreen( mask, region, data ); + if( client != NULL ) + capture_region = region; + } + +void VideoRecordEffect::postPaintScreen() + { + effects->postPaintScreen(); + if( client != NULL ) + { +#if 1 + if( CapturyProcessRegionStart( client ) == CAPTURY_SUCCESS ) + { + foreach( QRect r, capture_region.rects()) + { + int gly = displayHeight() - r.y() - r.height(); // opengl coords + CapturyProcessRegion( client, r.x(), gly, r.width(), r.height()); + } + CapturyProcessRegionCommit( client ); + } +#else + CapturyProcessFrame( client ); +#endif + } + } + +void VideoRecordEffect::startRecording() + { + if( client != NULL ) + stopRecording(); + bzero( &config, sizeof( config )); + config.x = area.x(); + config.y = area.y(); + config.width = area.width(); + config.height = area.height(); + config.scale = 0; + config.fps = 30; // TODO + config.deviceType = CAPTURY_DEVICE_GLX; // TODO + config.deviceHandle = display(); + config.windowHandle = rootWindow(); // TODO + config.cursor = true; + client = CapturyOpen( &config ); + if( client == NULL ) + { + kDebug( 1212 ) << "Video recording init failed" << endl; + return; + } + // TODO + if( CapturySetOutputFileName( client, "/tmp/kwin_video.cps" ) != CAPTURY_SUCCESS ) + { + kDebug( 1212 ) << "Video recording file open failed" << endl; + return; + } + workspace()->addRepaintFull(); // trigger reading initial screen contents into buffer + kDebug( 1212 ) << "Video recording start" << endl; + } + +void VideoRecordEffect::stopRecording() + { + if( client == NULL ) + return; + kDebug( 1212 ) << "Video recording stop" << endl; + CapturyClose( client ); + client = NULL; + } + +void VideoRecordEffect::toggleRecording() + { + if( client == NULL ) + startRecording(); + else + stopRecording(); + } + +} // namespace + +#include "videorecord.moc" diff --git a/effects/videorecord.h b/effects/videorecord.h new file mode 100644 index 0000000000..83b74c30bf --- /dev/null +++ b/effects/videorecord.h @@ -0,0 +1,45 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2006 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +// TODO MIT or some other licence, perhaps move to some lib + +#ifndef KWIN_VIDEO_H +#define KWIN_VIDEO_H + +#include + +#include + +namespace KWinInternal +{ + +class VideoRecordEffect + : public QObject, public Effect + { + Q_OBJECT + public: + VideoRecordEffect(); + virtual ~VideoRecordEffect(); + virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); + virtual void postPaintScreen(); + private slots: + void toggleRecording(); + private: + void startRecording(); + void stopRecording(); + captury_config_t config; + captury_t* client; + QRect area; + QRegion capture_region; + }; + +} // namespace + +#endif diff --git a/utils.h b/utils.h index 32d1f9449a..b7114b240c 100644 --- a/utils.h +++ b/utils.h @@ -14,6 +14,7 @@ License. See the file "COPYING" for the exact licensing terms. #include #include +#include #include