Skip to content

Commit

Permalink
[NUI.WindowSystem] Introduce the new KVM service feature
Browse files Browse the repository at this point in the history
Introduce the new KVM service feature and Add tests for the feature

Signed-off-by: Junseok Kim <[email protected]>
  • Loading branch information
juns-kim authored and dongsug-song committed Aug 21, 2023
1 parent 4795847 commit d8df023
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tizen.NUI.WindowSystem.Shell
{
internal static partial class Interop
{
internal static partial class KVMService
{
const string lib = "libtzsh_kvm_service.so.0";

[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_create")]
internal static extern IntPtr Create(IntPtr tzsh, IntPtr win);

[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_destroy")]
internal static extern int Destroy(IntPtr kvmService);

[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_perform_drop")]
internal static extern int PerformDrop(IntPtr kvmService);

[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_secondary_selection_set")]
internal static extern int SetSecondarySelection(IntPtr kvmService);

[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_secondary_selection_unset")]
internal static extern int UnsetSecondarySelection(IntPtr kvmService);

internal delegate void KVMDragStartEventCallback(IntPtr data, IntPtr kvmService);
[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_drag_start_cb_set")]
internal static extern int SetDragStartEventHandler(IntPtr kvmService, KVMDragStartEventCallback func, IntPtr data);

internal delegate void KVMDragEndEventCallback(IntPtr data, IntPtr kvmService);
[global::System.Runtime.InteropServices.DllImport(lib, EntryPoint = "tzsh_kvm_service_drag_end_cb_set")]
internal static extern int SetDragEndEventHandler(IntPtr kvmService, KVMDragEndEventCallback func, IntPtr data);
}
}
}
210 changes: 210 additions & 0 deletions src/Tizen.NUI.WindowSystem/src/public/KVMService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/*
* 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;

namespace Tizen.NUI.WindowSystem.Shell
{
/// <summary>
/// Class for the Tizen KVM service.
/// </summary>
/// This class is need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public class KVMService : IDisposable
{
private TizenShell _tzsh;
private IntPtr _kvmService;
private int _tzshWin;
private bool disposed = false;
private bool isDisposeQueued = false;

private Interop.KVMService.KVMDragStartEventCallback _onDragStarted;
private Interop.KVMService.KVMDragEndEventCallback _onDragEnded;

private event EventHandler _dragStarted;
private event EventHandler _dragEnded;

/// <summary>
/// Creates a new KVM Service handle.
/// </summary>
/// <param name="tzShell">The TizenShell instance.</param>
/// <param name="win">The window to provide service of the quickpanel.</param>
/// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
/// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
public KVMService(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();
_kvmService = Interop.KVMService.Create(_tzsh.GetNativeHandle(), (IntPtr)_tzshWin);
if (_kvmService == IntPtr.Zero)
{
int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
_tzsh.ErrorCodeThrow(err);
}
}

/// <summary>
/// Destructor.
/// </summary>
~KVMService()
{
if (!isDisposeQueued)
{
isDisposeQueued = true;
DisposeQueue.Instance.Add(this);
}
}

/// <summary>
/// Dispose.
/// </summary>
public void Dispose()
{
if (isDisposeQueued)
{
Dispose(DisposeTypes.Implicit);
}
else
{
Dispose(DisposeTypes.Explicit);
GC.SuppressFinalize(this);
}
}

/// <inheritdoc/>
protected virtual void Dispose(DisposeTypes type)
{
if (!disposed)
{
if (_kvmService != IntPtr.Zero)
{
int res = Interop.KVMService.Destroy(_kvmService);
_kvmService = IntPtr.Zero;
}
disposed = true;
}
}

/// <summary>
/// Emits the event when the drag started from any window.
/// </summary>
/// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
public event EventHandler DragStarted
{
add
{
if (_dragStarted == null)
{
_onDragStarted = OnDragStarted;
int res = Interop.KVMService.SetDragStartEventHandler(_kvmService, _onDragStarted, IntPtr.Zero);
_tzsh.ErrorCodeThrow(res);
}
_dragStarted += value;
}
remove
{
_dragStarted -= value;
if (_dragStarted == null)
{
int res = Interop.KVMService.SetDragStartEventHandler(_kvmService, null, IntPtr.Zero);
_tzsh.ErrorCodeThrow(res);
}
}
}

/// <summary>
/// Emits the event when the drag ended on any window except KVM window.
/// </summary>
/// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
public event EventHandler DragEnded
{
add
{
if (_dragEnded == null)
{
_onDragEnded = OnDragEnded;
int res = Interop.KVMService.SetDragEndEventHandler(_kvmService, _onDragEnded, IntPtr.Zero);
_tzsh.ErrorCodeThrow(res);
}
_dragEnded += value;
}
remove
{
_dragEnded -= value;
if (_dragEnded == null)
{
int res = Interop.KVMService.SetDragEndEventHandler(_kvmService, null, IntPtr.Zero);
_tzsh.ErrorCodeThrow(res);
}
}
}

private void OnDragStarted(IntPtr data, IntPtr softkeyService)
{
_dragStarted?.Invoke(this, EventArgs.Empty);
}

private void OnDragEnded(IntPtr data, IntPtr softkeyService)
{
_dragEnded?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Requests to perform drop to KVM window.
/// </summary>
/// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
public void PerformDrop()
{
int res = Interop.KVMService.PerformDrop(_kvmService);
_tzsh.ErrorCodeThrow(res);
}

/// <summary>
/// Requests to set KVM window as secondary selection window.
/// </summary>
/// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
public void SetSecondarySelction()
{
int res = Interop.KVMService.SetSecondarySelection(_kvmService);
_tzsh.ErrorCodeThrow(res);
}

/// <summary>
/// Requests to unset secondary selection window of KVM window.
/// </summary>
/// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
public void UnsetSecondarySelction()
{
int res = Interop.KVMService.UnsetSecondarySelection(_kvmService);
_tzsh.ErrorCodeThrow(res);
}
}
}
Loading

0 comments on commit d8df023

Please sign in to comment.