--- kwin/scripts.h.sav 2008-03-19 13:07:35.000000000 +0100 +++ kwin/scripts.h 2001-01-01 01:01:00.000000000 +0100 @@ -0,0 +1,61 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2008 Lubos Lunak + +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_SCRIPTS_H +#define KWIN_SCRIPTS_H + +#include + +namespace KWin +{ + +class Client; +class ScriptWindow; + +class Scripts + { + public: + static int checkDesktop( Client*c, int desktop, bool initial = false ); + }; + +class ScriptWindow + : public QObject + { + Q_OBJECT + Q_PROPERTY( QString resourceClass READ resourceClass ) + Q_PROPERTY( QString resourceName READ resourceName ) + Q_PROPERTY( QString windowRole READ windowRole ) + Q_PROPERTY( QString caption READ caption ); + Q_PROPERTY( int desktop READ desktop WRITE setDesktop ) + public: + ScriptWindow( Client* c ); + QString resourceClass() const; + QString resourceName() const; + QString windowRole() const; + QString caption() const; + int desktop() const; + void setDesktop( int desktop ); + private: + Client* c; + }; + +} // namespace + +#endif --- kwin/CMakeLists.txt.sav 2008-01-19 18:21:52.000000000 +0100 +++ kwin/CMakeLists.txt 2008-03-19 14:04:32.000000000 +0100 @@ -85,6 +85,7 @@ set(kwin_KDEINIT_SRCS deleted.cpp effects.cpp compositingprefs.cpp + scripts.cpp ) qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.xml workspace.h KWin::Workspace ) @@ -93,7 +94,7 @@ qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS kde4_add_kdeinit_executable( kwin ${kwin_KDEINIT_SRCS}) -target_link_libraries(kdeinit_kwin ${KDE4_KDEUI_LIBS} kdecorations kwineffects ${X11_LIBRARIES}) +target_link_libraries(kdeinit_kwin ${KDE4_KDEUI_LIBS} ${QT_QTSCRIPT_LIBRARY} kdecorations kwineffects ${X11_LIBRARIES}) if(OPENGL_FOUND) target_link_libraries(kdeinit_kwin ${OPENGL_gl_LIBRARY}) # -ldl used by OpenGL code --- kwin/manage.cpp.sav 2008-03-14 21:25:46.000000000 +0100 +++ kwin/manage.cpp 2008-03-19 13:54:49.000000000 +0100 @@ -35,6 +35,7 @@ along with this program. If not, see #include "rules.h" #include "group.h" +#include "scripts.h" namespace KWin { @@ -196,6 +197,7 @@ bool Client::manage( Window w, bool isMa if ( desk == 0 ) // assume window wants to be visible on the current desktop desk = workspace()->currentDesktop(); desk = rules()->checkDesktop( desk, !isMapped ); + desk = Scripts::checkDesktop( this, desk, !isMapped ); if( desk != NET::OnAllDesktops ) // do range check desk = qMax( 1, qMin( workspace()->numberOfDesktops(), desk )); info->setDesktop( desk ); --- kwin/client.cpp.sav 2008-03-07 20:43:29.000000000 +0100 +++ kwin/client.cpp 2008-03-19 13:54:42.000000000 +0100 @@ -42,6 +42,7 @@ along with this program. If not, see #include @@ -1180,6 +1181,7 @@ void Client::setDesktop( int desktop ) if( desktop != NET::OnAllDesktops ) // do range check desktop = qMax( 1, qMin( workspace()->numberOfDesktops(), desktop )); desktop = rules()->checkDesktop( desktop ); + desktop = Scripts::checkDesktop( this, desktop ); if( desk == desktop ) return; int was_desk = desk; --- kwin/scripts.cpp.sav 2008-03-19 13:06:46.000000000 +0100 +++ kwin/scripts.cpp 2008-03-19 14:17:45.000000000 +0100 @@ -0,0 +1,81 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2008 Lubos Lunak + +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 "scripts.h" + +#include + +#include "client.h" + +namespace KWin +{ + +int Scripts::checkDesktop( Client* c, int desktop, bool initial ) + { + ScriptWindow w( c ); + QScriptEngine engine; + QScriptValue sw = engine.newQObject( &w ); + engine.globalObject().setProperty( "window", sw ); + QScriptValue sd( &engine, desktop ); + engine.globalObject().setProperty( "desktop", sd ); + QScriptValue si( &engine, initial ); + engine.globalObject().setProperty( "initial", si ); + QString script = "" + "if( window.resourceClass == 'xterm' && initial )" + " {" + " print( 'New window is an XTerm, opening on desktop 2.' );" + " return 2;" + " }" + "print( 'Window ' + window.resourceClass + ', desktop ' + desktop + ', initial:' + initial );" + "return desktop;" + ; + return engine.evaluate( script ).toNumber(); + } + +ScriptWindow::ScriptWindow( Client* c ) + : c( c ) + { + } + +#define MAP_GET( name, type ) \ +type ScriptWindow::name() const \ + { \ + return c->name(); \ + } + +#define MAP_SET( name, type ) \ +void ScriptWindow::name( type value ) \ + { \ + c->name( value ); \ + } + +MAP_GET( resourceClass, QString ) +MAP_GET( resourceName, QString ) +MAP_GET( windowRole, QString ) +MAP_GET( caption, QString ) +MAP_GET( desktop, int ) +MAP_SET( setDesktop, int ) + +#undef MAP_GET +#undef MAP_SET + +} + +#include "scripts.moc"