//newWrapper does not search clientMap for existing entries
//a search must be performed prior to this call.
//However, since now clientMap is actually a QHash, it wouldn't
//hurt to perform a check here as well.
SWrapper::ClientResolution SWrapper::Client::newWrapper(KWin::Client* client, QScriptEngine* eng)
{
SWrapper::Client* wrapper = new SWrapper::Client(client);
wrapper->setEngine(eng);
QScriptValue value;
// Use this value to avoid repeated function generations
// for function aliases.
QScriptValue func;
/*
* Step1: Prepping
* Connect all signals and slots from client to
* the wrapper object.
*/
//End of prepping
/*
* Step2: Conversion
* Wrap the object, set the data parameter
* and obtain a QScriptValue
*/
value = eng->newQObject(wrapper,
QScriptEngine::AutoOwnership,
QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater
);
wrapper->tl_centralObject = client;
tl_append(value, eng);
//End of Conversion
/*
* Step3: Spice
* Add the static functions and other things
* that rely on the value of data() and not the
* wrapper address.
*/
value.setProperty("caption", eng->newFunction(caption, 0), QScriptValue::Undeletable);
value.setProperty("close", eng->newFunction(close, 0), QScriptValue::Undeletable);
value.setProperty("resize", eng->newFunction(resize, 1), QScriptValue::Undeletable);
value.setProperty("move", eng->newFunction(move, 1), QScriptValue::Undeletable);
value.setProperty("setGeometry", eng->newFunction(setGeometry, 1), QScriptValue::Undeletable);
value.setProperty("getWindowInfo", eng->newFunction(getWindowInfo, 0), QScriptValue::Undeletable);
value.setProperty("isTransient", eng->newFunction(isTransient, 0), QScriptValue::Undeletable);
value.setProperty("transientFor", eng->newFunction(transientFor, 0), QScriptValue::Undeletable);
value.setProperty("activate", eng->newFunction(activate, 1), QScriptValue::Undeletable);
value.setProperty("setCaption", eng->newFunction(setCaption, 1), QScriptValue::Undeletable);
value.setProperty("setFullScreen", eng->newFunction(setFullScreen, 2), QScriptValue::Undeletable);
value.setProperty("isFullScreen", eng->newFunction(isFullScreen, 0), QScriptValue::Undeletable);
value.setProperty("isFullScreenable", eng->newFunction(isFullScreenable, 0), QScriptValue::Undeletable);
value.setProperty("minimize", eng->newFunction(minimize, 0), QScriptValue::Undeletable);
value.setProperty("clientGroup", eng->newFunction(clientGroup, 0), QScriptValue::Undeletable);
value.setProperty("maximize", eng->newFunction(maximize, 0), QScriptValue::Undeletable);
value.setProperty("setMaximize", eng->newFunction(setMaximize, 2), QScriptValue::Undeletable);
value.setProperty("desktop", eng->newFunction(desktop, 0), QScriptValue::Undeletable);
value.setProperty("setKeepAbove", eng->newFunction(setKeepAbove, 0), QScriptValue::Undeletable);
value.setProperty("setKeepBelow", eng->newFunction(setKeepBelow, 0), QScriptValue::Undeletable);
BOOLATTACHCLIENT(isShade)
BOOLATTACHCLIENT(isShadeable)
BOOLATTACHCLIENT(isMinimized)
BOOLATTACHCLIENT(isMinimizable)
BOOLATTACHCLIENT(isMaximizable)
BOOLATTACHCLIENT(isResizable)
BOOLATTACHCLIENT(isMovable)
BOOLATTACHCLIENT(isMovableAcrossScreens)
BOOLATTACHCLIENT(isCloseable)
BOOLATTACHCLIENT(keepAbove)
BOOLATTACHCLIENT(keepBelow)
func = eng->newFunction(unminimize, 0);
value.setProperty("unminimize", func, QScriptValue::Undeletable);
value.setProperty("restore", func, QScriptValue::Undeletable);
ClientResolution final(wrapper, value);
//Finally, append the entire thing to the clientMap
//clientMap.insert(const_cast<KWin::Client*>(client), ClientResolution(wrapper, value));
//And.. we're done
(client->scriptCache)->insert(eng, final);
return final;
}