Skip to content

Commit

Permalink
introduce the Screensaver service feature
Browse files Browse the repository at this point in the history
  • Loading branch information
doyoun-kang authored and dongsug-song committed Sep 2, 2024
1 parent 63f4b54 commit 9ac066b
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
144 changes: 144 additions & 0 deletions src/Tizen.NUI.WindowSystem/src/public/ScreensaverService.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Program : NUIApplication
TextLabel textSoftkeyServiceExpand;
TextLabel textSoftkeyServiceOpacity;

Shell.ScreensaverService screensaverService;
Button BtnScreensaverService;
TextLabel textScreensaverServiceTitle;

protected override void OnCreate()
{
base.OnCreate();
Expand All @@ -60,35 +64,45 @@ void Initialize()
{
Text = "QuickPanelService",
Size = new Size(400, 100),
Position = new Position(100, 400),
Position = new Position(100, 340),
Margin = 10,
};

BtnSoftkeyClient = new Button()
{
Text = "SoftkeyClient",
Size = new Size(400, 100),
Position = new Position(100, 600),
Position = new Position(100, 480),
Margin = 10,
};

BtnSoftkeyService = new Button()
{
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,
};

window.Add(BtnClient);
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();

Expand Down Expand Up @@ -122,6 +136,7 @@ private void BtnClient_ClickEvent(object sender, Button.ClickEventArgs e)

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);
Expand Down Expand Up @@ -238,6 +253,7 @@ private void BtnService_ClickEvent(object sender, Button.ClickEventArgs e)

window.Remove(BtnService);
window.Remove(BtnClient);
window.Remove(BtnScreensaverService);
window.Remove(BtnSoftkeyService);
window.Remove(BtnSoftkeyClient);
qpService = new Shell.QuickPanelService(tzShell, (IWindowProvider)window, type);
Expand Down Expand Up @@ -409,6 +425,7 @@ private void BtnSoftkeyClient_ClickEvent(object sender, Button.ClickEventArgs e)

window.Remove(BtnService);
window.Remove(BtnClient);
window.Remove(BtnScreensaverService);
window.Remove(BtnSoftkeyService);
window.Remove(BtnSoftkeyClient);
softkeyClient = new Shell.SoftkeyClient(tzShell, (IWindowProvider)window);
Expand Down Expand Up @@ -553,6 +570,7 @@ private void BtnSoftkeyService_ClickEvent(object sender, Button.ClickEventArgs e

window.Remove(BtnService);
window.Remove(BtnClient);
window.Remove(BtnScreensaverService);
window.Remove(BtnSoftkeyService);
window.Remove(BtnSoftkeyClient);
softkeyService = new Shell.SoftkeyService(tzShell, (IWindowProvider)window);
Expand Down Expand Up @@ -647,6 +665,30 @@ private void BtnSoftkeyServiceHide_ClickEvent(object sender, Button.ClickEventAr
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();
Expand Down

0 comments on commit 9ac066b

Please sign in to comment.