From: Doyoun Kang Date: Wed, 14 Aug 2024 00:40:33 +0000 (+0900) Subject: introduce the Screensaver service feature X-Git-Tag: submit/tizen/20240902.151039~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ac066b9af630171009579526935a1f02f63cb38;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git introduce the Screensaver service feature --- 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 index 000000000..f01f0ea3f --- /dev/null +++ b/src/Tizen.NUI.WindowSystem/src/internal/Interop/Interop.ScreensaverService.cs @@ -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 index 000000000..a31a10154 --- /dev/null +++ b/src/Tizen.NUI.WindowSystem/src/public/ScreensaverService.cs @@ -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 +{ + /// + /// Class for the Tizen screensaver service. + /// + /// 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; + + /// + /// Creates a new Screensaver Service handle. + /// + /// The TizenShell instance. + /// The window to provide service of the screensaver. + /// Thrown when failed of invalid argument. + /// Thrown when an argument is null. + 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); + } + } + + /// + /// Creates a new Screensaver Service handle. + /// + /// The TizenShell instance. + /// The window provider for the screensaver service. + /// Thrown when failed of invalid argument. + /// Thrown when an argument is null. + 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); + } + } + + /// + /// Destructor. + /// + ~ScreensaverService() + { + Dispose(disposing: false); + } + /// + /// Dispose. + /// + public void Dispose() + { + if (disposed) + return; + + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + /// + 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); + } + } +} diff --git a/test/Tizen.NUI.WindowSystem.Samples/Tizen.NUI.WindowSystem.Samples.cs b/test/Tizen.NUI.WindowSystem.Samples/Tizen.NUI.WindowSystem.Samples.cs index b2ae9564b..365bdd36c 100644 --- a/test/Tizen.NUI.WindowSystem.Samples/Tizen.NUI.WindowSystem.Samples.cs +++ b/test/Tizen.NUI.WindowSystem.Samples/Tizen.NUI.WindowSystem.Samples.cs @@ -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();