Permalink
Browse files

Enable python-based screensavers

- Extension point needs to be "xbmc.ui.screensaver"
- Python script needs to exit itself after receiving an onScreensaverDeactivated announcement
- If a script doesn't exit itself in 5 seconds, it will be stopped by force

*Based on dersphere's implementation
  • Loading branch information...
1 parent 9361a5b commit 87f3facf6d450393824a3d0bfa564eaa7c13d575 @garbear garbear committed Aug 4, 2012
Showing with 36 additions and 1 deletion.
  1. +2 −1 xbmc/addons/AddonDll.h
  2. +6 −0 xbmc/addons/AddonManager.cpp
  3. +28 −0 xbmc/addons/ScreenSaver.cpp
View
@@ -81,7 +81,8 @@ template<class TheDll, typename TheStruct, typename TheProps>
CAddonDll<TheDll, TheStruct, TheProps>::CAddonDll(const cp_extension_t *ext)
: CAddon(ext)
{
- if (ext)
+ // if library attribute isn't present, look for a system-dependent one
+ if (ext && m_strLibName.IsEmpty())
{
#if defined(_LINUX) && !defined(TARGET_DARWIN)
m_strLibName = CAddonMgr::Get().GetExtValue(ext->configuration, "@library_linux");
@@ -116,6 +116,12 @@ AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
{ // built in screensaver
return AddonPtr(new CAddon(props));
}
+ if (type == ADDON_SCREENSAVER)
+ { // Python screensaver
+ CStdString library = CAddonMgr::Get().GetExtValue(props->configuration, "@library");
+ if (URIUtils::GetExtension(library).Equals(".py", false))
+ return AddonPtr(new CScreenSaver(props));
+ }
#if defined(_LINUX) && !defined(TARGET_DARWIN)
if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_linux")) && value.empty())
break;
@@ -22,6 +22,16 @@
#include "settings/Settings.h"
#include "windowing/WindowingFactory.h"
+#ifdef HAS_PYTHON
+#include "interfaces/python/XBPython.h"
+#include "utils/AlarmClock.h"
+
+// What sound does a python screensaver make?
+#define PYTHON_ALARM "sssssscreensaver"
+
+#define PYTHON_SCRIPT_TIMEOUT 5 // seconds
+#endif
+
namespace ADDON
{
@@ -32,6 +42,17 @@ namespace ADDON
bool CScreenSaver::CreateScreenSaver()
{
+#ifdef HAS_PYTHON
+ if (URIUtils::GetExtension(LibPath()).Equals(".py", false))
+ {
+ // Don't allow a previously-scheduled alarm to kill our new screensaver
+ g_alarmClock.Stop(PYTHON_ALARM);
+
+ if (!g_pythonParser.StopScript(LibPath()))
+ g_pythonParser.evalFile(LibPath(), AddonPtr(new CScreenSaver(Props())));
+ return true;
+ }
+#endif
// pass it the screen width,height
// and the name of the screensaver
int iWidth = g_graphicsContext.GetWidth();
@@ -78,6 +99,13 @@ void CScreenSaver::GetInfo(SCR_INFO *info)
void CScreenSaver::Destroy()
{
+#ifdef HAS_PYTHON
+ if (URIUtils::GetExtension(LibPath()).Equals(".py", false))
+ {
+ g_alarmClock.Start(PYTHON_ALARM, PYTHON_SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false);
+ return;
+ }
+#endif
// Release what was allocated in method CScreenSaver::CreateScreenSaver.
if (m_pInfo)
{

0 comments on commit 87f3fac

Please sign in to comment.