Modifying More Menu and Uninstall Popup for TaskbarService Window
[profile/iot/apps/dotnet/taskbar.git] / TaskBar / Common / DeviceInfo.cs
index 88f3b8f..2e719f8 100644 (file)
@@ -1,4 +1,5 @@
 using Tizen.NUI;
+using Tizen.NUI.WindowSystem.Shell;
 
 namespace TaskBar.Common
 {
@@ -7,6 +8,7 @@ namespace TaskBar.Common
         private int width;
         private int height;
         private Window.WindowOrientation orientation;
+        private Window.WindowOrientation naturalDeviceOrientation;
 
         private static readonly DeviceInfo instance = new DeviceInfo();
 
@@ -16,6 +18,8 @@ namespace TaskBar.Common
             height = Window.Instance.Size.Height;
             IsPortrait = width < height;
             orientation = Window.Instance.GetCurrentOrientation();
+            naturalDeviceOrientation = Window.Instance.GetCurrentOrientation();
+            TaskbarPosition = TaskbarService.PlaceType.Bottom;
             if (orientation == Window.WindowOrientation.Portrait || orientation == Window.WindowOrientation.PortraitInverse)
             {
                 if (IsPortrait == false)
@@ -34,6 +38,8 @@ namespace TaskBar.Common
         public void UpdateDeviceInfo()
         {
             Window.WindowOrientation currentOrientation = Window.Instance.GetCurrentOrientation();
+            Tizen.Log.Info(Resources.LogTag, "new Orientation: " + currentOrientation);
+            UpdateTaskbarPosition(currentOrientation);
             if (orientation == Window.WindowOrientation.Portrait || orientation == Window.WindowOrientation.PortraitInverse)
             {
                 if (currentOrientation == Window.WindowOrientation.Landscape || currentOrientation == Window.WindowOrientation.LandscapeInverse)
@@ -51,6 +57,34 @@ namespace TaskBar.Common
             orientation = currentOrientation;
         }
 
+        public void SetFullInputRegion()
+        {
+            Window.Instance.SetInputRegion(new Rectangle(0, 0, width, height));
+        }
+
+        public void SetTaskbarInputRegion()
+        {
+            int sizeWidth = width;
+            int sizeHeight = Resources.TaskbarHeight.SpToPx();
+            int positionX = 0;
+            int positionY = height - sizeHeight;
+            Window.Instance.SetInputRegion(new Rectangle(positionX, positionY, sizeWidth, sizeHeight));
+        }
+
+        private void UpdateTaskbarPosition(Window.WindowOrientation newOrientation)
+        {
+            int difference = (newOrientation - naturalDeviceOrientation) / 90;
+            difference = difference >= 0 ? difference : 4 + difference;
+            TaskbarPosition = difference switch
+            {
+                1 => TaskbarService.PlaceType.Left,
+                2 => TaskbarService.PlaceType.Top,
+                3 => TaskbarService.PlaceType.Right,
+                _ => TaskbarService.PlaceType.Bottom,
+            };
+            Tizen.Log.Info(Resources.LogTag, "new Position: " + TaskbarPosition);
+        }
+
         private void ToggleOrientation()
         {
             (width, height) = (height, width);
@@ -62,5 +96,7 @@ namespace TaskBar.Common
         public int DisplayWidth { get => width; }
 
         public int DisplayHeight { get => height; }
+
+        public TaskbarService.PlaceType TaskbarPosition { get; private set; }
     }
 }