[vlc-commits] inhibit: add UIKit-based inhibiter
Alexandre Janniaux
git at videolan.org
Thu Apr 15 14:08:05 UTC 2021
vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Apr 14 11:42:58 2021 +0200| [a24a9b28992c66731354c2c8448e31f5f4ed37ba] | committer: Alexandre Janniaux
inhibit: add UIKit-based inhibiter
The inhibiter code is taken from VLCKit inhibiter's handling, and is
meant to replace this handling.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a24a9b28992c66731354c2c8448e31f5f4ed37ba
---
modules/misc/Makefile.am | 12 ++++++-
modules/misc/inhibit/uikit-inhibit.m | 67 ++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/modules/misc/Makefile.am b/modules/misc/Makefile.am
index bc3252ab22..ef024f3a20 100644
--- a/modules/misc/Makefile.am
+++ b/modules/misc/Makefile.am
@@ -52,6 +52,17 @@ libiokit_inhibit_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation
misc_LTLIBRARIES += libiokit_inhibit_plugin.la
endif
+libuikit_inhibit_plugin_la_SOURCES = misc/inhibit/uikit-inhibit.m
+libuikit_inhibit_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,UIKit,-framework,Foundation
+libuikit_inhibit_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-arc
+if HAVE_IOS
+misc_LTLIBRARIES += libuikit_inhibit_plugin.la
+endif
+
+if HAVE_TVOS
+misc_LTLIBRARIES += libuikit_inhibit_plugin.la
+endif
+
libxdg_screensaver_plugin_la_SOURCES = misc/inhibit/xdg.c
if HAVE_XCB
if !HAVE_WIN32
@@ -129,4 +140,3 @@ libmedialibrary_plugin_la_LIBADD = $(MEDIALIBRARY_LIBS)
libmedialibrary_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(miscdir)'
EXTRA_LTLIBRARIES += libmedialibrary_plugin.la
misc_LTLIBRARIES += $(LTLIBmedialibrary)
-
diff --git a/modules/misc/inhibit/uikit-inhibit.m b/modules/misc/inhibit/uikit-inhibit.m
new file mode 100644
index 0000000000..ab5536d4e6
--- /dev/null
+++ b/modules/misc/inhibit/uikit-inhibit.m
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright © 2021 Videolabs
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/**
+ * \file uikit-inhibit.m
+ * \brief iOS display and idle sleep inhibitor using UIKit
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_inhibit.h>
+#include <vlc_vout_window.h>
+
+#include <UIKit/UIKit.h>
+
+static void UpdateInhibit(vlc_inhibit_t *ih, unsigned mask)
+{
+ [UIApplication sharedApplication].idleTimerDisabled =
+ (mask & VLC_INHIBIT_DISPLAY) == VLC_INHIBIT_DISPLAY;
+}
+
+static int OpenInhibit(vlc_object_t *obj)
+{
+ vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
+ vout_window_t *wnd = vlc_inhibit_GetWindow(ih);
+ if (wnd->type != VOUT_WINDOW_TYPE_NSOBJECT)
+ return VLC_EGENERIC;
+
+ UIView * view = (__bridge UIView*)wnd->handle.nsobject;
+
+ if (unlikely(![view respondsToSelector:@selector(isKindOfClass:)]))
+ return VLC_EGENERIC;
+
+ if (![view isKindOfClass:[UIView class]])
+ return VLC_EGENERIC;
+
+ ih->inhibit = UpdateInhibit;
+ return VLC_SUCCESS;
+}
+
+vlc_module_begin()
+ set_shortname("UIKit sleep inhibition")
+ set_description("UIKit screen sleep inhibition for iOS and tvOS")
+ set_category(CAT_ADVANCED)
+ set_subcategory(SUBCAT_ADVANCED_MISC)
+ set_capability("inhibit", 10)
+ set_callback(OpenInhibit)
+vlc_module_end()
More information about the vlc-commits
mailing list