introduce the Screensaver service feature
authorDoyoun Kang <doyoun.kang@samsung.com>
Wed, 14 Aug 2024 00:40:33 +0000 (09:40 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 2 Sep 2024 08:38:16 +0000 (17:38 +0900)
src/Tizen.NUI.WindowSystem/src/internal/Interop/Interop.ScreensaverService.cs [new file with mode: 0644]
src/Tizen.NUI.WindowSystem/src/public/ScreensaverService.cs [new file with mode: 0644]
test/Tizen.NUI.WindowSystem.Samples/Tizen.NUI.WindowSystem.Samples.cs

diff --git a/src/Tizen.NUI.WindowSystem/src/internal/Interop/Interop.ScreensaverService.cs b/src/Tizen.NUI.WindowSystem/src/internal/Interop/Interop.ScreensaverService.cs
new file mode 100644 (file)
index 0000000..f01f0ea
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tizen.NUI.WindowSystem.Shell
+{
+    internal static partial class Interop
+    {
+        internal static partial class ScreensaverService
+        {
+            const string lib = "libtzsh_screensaver_service.so.0";
+
+            [global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_screensaver_service_create")]
+            internal static extern IntPtr Create(IntPtr tzsh, uint win);
+
+            [global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_screensaver_service_destroy")]
+            internal static extern int Destroy(IntPtr ScreensaverService);
+        }
+    }
+}
diff --git a/src/Tizen.NUI.WindowSystem/src/public/ScreensaverService.cs b/src/Tizen.NUI.WindowSystem/src/public/ScreensaverService.cs
new file mode 100644 (file)
index 0000000..a31a101
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Copyright(c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+using System.Collections.Generic;
+using Tizen.Common;
+using Tizen.Applications;
+
+namespace Tizen.NUI.WindowSystem.Shell
+{
+    /// <summary>
+    /// Class for the Tizen screensaver service.
+    /// </summary>
+    /// This class is need to be hidden as inhouse API.
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class ScreensaverService : IDisposable
+    {
+        private TizenShell _tzsh;
+        private IntPtr _screensaverService;
+        private int _tzshWin;
+        private bool disposed = false;
+        private bool isDisposeQueued = false;
+
+        /// <summary>
+        /// Creates a new Screensaver Service handle.
+        /// </summary>
+        /// <param name="tzShell">The TizenShell instance.</param>
+        /// <param name="win">The window to provide service of the screensaver.</param>
+        /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
+        /// <exception cref="ArgumentNullException">Thrown when an argument is null.</exception>
+        public ScreensaverService(TizenShell tzShell, Window win)
+        {
+            if (tzShell == null)
+            {
+                throw new ArgumentNullException(nameof(tzShell));
+            }
+            if (tzShell.GetNativeHandle() == IntPtr.Zero)
+            {
+                throw new ArgumentException("tzShell is not initialized.");
+            }
+            if (win == null)
+            {
+                throw new ArgumentNullException(nameof(win));
+            }
+
+            _tzsh = tzShell;
+            _tzshWin = win.GetNativeId();
+            _screensaverService = Interop.ScreensaverService.Create(_tzsh.GetNativeHandle(), (uint)_tzshWin);
+            if (_screensaverService == IntPtr.Zero)
+            {
+                int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
+                _tzsh.ErrorCodeThrow(err);
+            }
+        }
+
+        /// <summary>
+        /// Creates a new Screensaver Service handle.
+        /// </summary>
+        /// <param name="tzShell">The TizenShell instance.</param>
+        /// <param name="win">The window provider for the screensaver service.</param>
+        /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
+        /// <exception cref="ArgumentNullException">Thrown when an argument is null.</exception>
+        public ScreensaverService(TizenShell tzShell, IWindowProvider win)
+        {
+            if (tzShell == null)
+            {
+                throw new ArgumentNullException(nameof(tzShell));
+            }
+            if (tzShell.GetNativeHandle() == IntPtr.Zero)
+            {
+                throw new ArgumentException("tzShell is not initialized.");
+            }
+            if (win == null)
+            {
+                throw new ArgumentNullException(nameof(win));
+            }
+
+            _tzsh = tzShell;
+            _tzshWin = WindowSystem.Interop.EcoreWl2.GetWindowId(win.WindowHandle);
+            _screensaverService = Interop.ScreensaverService.Create(_tzsh.GetNativeHandle(), (uint)_tzshWin);
+            if (_screensaverService == IntPtr.Zero)
+            {
+                int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
+                _tzsh.ErrorCodeThrow(err);
+            }
+        }
+
+        /// <summary>
+        /// Destructor.
+        /// </summary>
+        ~ScreensaverService()
+        {
+            Dispose(disposing: false);
+        }
+        /// <summary>
+        /// Dispose.
+        /// </summary>
+        public void Dispose()
+        {
+            if (disposed)
+                return;
+
+            Dispose(disposing: true);
+            GC.SuppressFinalize(this);
+        }
+        /// <inheritdoc/>
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposed)
+            {
+                if (disposing)
+                {
+                    ReleaseHandle(_screensaverService);
+                }
+                else
+                {
+                    var handle = _screensaverService;
+                    CoreApplication.Post(() => ReleaseHandle(handle));
+                }
+                disposed = true;
+            }
+        }
+
+        private void ReleaseHandle(IntPtr handle)
+        {
+            Interop.ScreensaverService.Destroy(handle);
+        }
+    }
+}
index b2ae9564be182294336b4d31b61e3d1173bb6cf5..365bdd36cbffa72bd06c59e8c144f86941c4c1a4 100644 (file)
@@ -36,6 +36,10 @@ namespace Tizen.NUI.WindowSystem.Samples
         TextLabel textSoftkeyServiceExpand;
         TextLabel textSoftkeyServiceOpacity;
 
+        Shell.ScreensaverService screensaverService;
+        Button BtnScreensaverService;
+        TextLabel textScreensaverServiceTitle;
+               
         protected override void OnCreate()
         {
             base.OnCreate();
@@ -60,7 +64,7 @@ namespace Tizen.NUI.WindowSystem.Samples
             {
                 Text = "QuickPanelService",
                 Size = new Size(400, 100),
-                Position = new Position(100, 400),
+                Position = new Position(100, 340),
                 Margin = 10,
             };
 
@@ -68,7 +72,7 @@ namespace Tizen.NUI.WindowSystem.Samples
             {
                 Text = "SoftkeyClient",
                 Size = new Size(400, 100),
-                Position = new Position(100, 600),
+                Position = new Position(100, 480),
                 Margin = 10,
             };
 
@@ -76,7 +80,15 @@ namespace Tizen.NUI.WindowSystem.Samples
             {
                 Text = "SoftkeyService",
                 Size = new Size(400, 100),
-                Position = new Position(100, 800),
+                Position = new Position(100, 620),
+                Margin = 10,
+            };
+
+            BtnScreensaverService = new Button()
+            {
+                Text = "ScreensaverService",
+                Size = new Size(400, 100),
+                Position = new Position(100, 760),
                 Margin = 10,
             };
 
@@ -84,11 +96,13 @@ namespace Tizen.NUI.WindowSystem.Samples
             window.Add(BtnService);
             window.Add(BtnSoftkeyClient);
             window.Add(BtnSoftkeyService);
+            window.Add(BtnScreensaverService);
 
             BtnClient.ClickEvent += BtnClient_ClickEvent;
             BtnService.ClickEvent += BtnService_ClickEvent;
             BtnSoftkeyClient.ClickEvent += BtnSoftkeyClient_ClickEvent;
             BtnSoftkeyService.ClickEvent += BtnSoftkeyService_ClickEvent;
+            BtnScreensaverService.ClickEvent += BtnScreensaverService_ClickEvent;
 
             tzShell = new Shell.TizenShell();
 
@@ -122,6 +136,7 @@ namespace Tizen.NUI.WindowSystem.Samples
 
             window.Remove(BtnService);
             window.Remove(BtnClient);
+            window.Remove(BtnScreensaverService);
             window.Remove(BtnSoftkeyService);
             window.Remove(BtnSoftkeyClient);
             qpClient = new Shell.QuickPanelClient(tzShell, (IWindowProvider)window, Shell.QuickPanelClient.Types.SystemDefault);
@@ -238,6 +253,7 @@ namespace Tizen.NUI.WindowSystem.Samples
 
             window.Remove(BtnService);
             window.Remove(BtnClient);
+            window.Remove(BtnScreensaverService);
             window.Remove(BtnSoftkeyService);
             window.Remove(BtnSoftkeyClient);
             qpService = new Shell.QuickPanelService(tzShell, (IWindowProvider)window, type);
@@ -409,6 +425,7 @@ namespace Tizen.NUI.WindowSystem.Samples
 
             window.Remove(BtnService);
             window.Remove(BtnClient);
+            window.Remove(BtnScreensaverService);
             window.Remove(BtnSoftkeyService);
             window.Remove(BtnSoftkeyClient);
             softkeyClient = new Shell.SoftkeyClient(tzShell, (IWindowProvider)window);
@@ -553,6 +570,7 @@ namespace Tizen.NUI.WindowSystem.Samples
 
             window.Remove(BtnService);
             window.Remove(BtnClient);
+            window.Remove(BtnScreensaverService);
             window.Remove(BtnSoftkeyService);
             window.Remove(BtnSoftkeyClient);
             softkeyService = new Shell.SoftkeyService(tzShell, (IWindowProvider)window);
@@ -647,6 +665,30 @@ namespace Tizen.NUI.WindowSystem.Samples
             softkeyService.Hide();
         }
 
+        private void BtnScreensaverService_ClickEvent(object sender, Button.ClickEventArgs e)
+        {
+            Window window = NUIApplication.GetDefaultWindow();
+            window.WindowSize = new Size(1920, 1080);
+            window.WindowPosition = new Position(0, 0);
+
+            window.Remove(BtnService);
+            window.Remove(BtnClient);
+            window.Remove(BtnScreensaverService);
+            window.Remove(BtnSoftkeyService);
+            window.Remove(BtnSoftkeyClient);
+            screensaverService = new Shell.ScreensaverService(tzShell, (IWindowProvider)window);
+
+            textScreensaverServiceTitle = new TextLabel($"Screen Saver");
+            textScreensaverServiceTitle.Position = new Position(0, 0);
+            textScreensaverServiceTitle.HorizontalAlignment = HorizontalAlignment.Center;
+            textScreensaverServiceTitle.VerticalAlignment = VerticalAlignment.Center;
+            textScreensaverServiceTitle.TextColor = Color.Blue;
+            textScreensaverServiceTitle.PointSize = 12.0f;
+            textScreensaverServiceTitle.HeightResizePolicy = ResizePolicyType.FillToParent;
+            textScreensaverServiceTitle.WidthResizePolicy = ResizePolicyType.FillToParent;
+            window.Add(textScreensaverServiceTitle);
+        }
+
         static void Main(string[] args)
         {
             var app = new Program();