|
1 | 1 | using System; |
2 | | -using System.Runtime.InteropServices; |
3 | 2 | using UnityEngine; |
| 3 | +using X11; |
4 | 4 |
|
5 | 5 | public class RemoveTaskbarApp : MonoBehaviour |
6 | 6 | { |
7 | | - [DllImport("user32.dll", SetLastError = true)] |
8 | | - static extern IntPtr FindWindow(string lpClassName, string lpWindowName); |
9 | 7 |
|
10 | | - [DllImport("user32.dll")] |
11 | | - static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); |
12 | | - |
13 | | - [DllImport("user32.dll")] |
14 | | - static extern int GetWindowLong(IntPtr hWnd, int nIndex); |
15 | | - |
16 | | - [DllImport("user32.dll")] |
17 | | - static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); |
18 | | - |
19 | | - [DllImport("user32.dll")] |
20 | | - static extern bool SetForegroundWindow(IntPtr hWnd); |
21 | | - |
22 | | - const int GWL_EXSTYLE = -20; |
23 | | - const int WS_EX_TOOLWINDOW = 0x00000080; |
24 | | - const int SW_RESTORE = 9; |
25 | | - |
26 | | - private static IntPtr unityHWND = IntPtr.Zero; |
| 8 | + private IntPtr _unityHwnd = IntPtr.Zero; |
27 | 9 |
|
28 | 10 | private bool _isHidden = true; |
29 | 11 | public bool IsHidden => _isHidden; |
30 | 12 |
|
31 | 13 | void Start() |
32 | 14 | { |
33 | | -#if UNITY_STANDALONE_WIN && !UNITY_EDITOR |
34 | | - unityHWND = GetUnityWindow(); |
35 | | - if (unityHWND != IntPtr.Zero) |
| 15 | +#if UNITY_STANDALONE_LINUX && !UNITY_EDITOR |
| 16 | + _unityHwnd = X11Manager.Instance.UnityWindow; |
| 17 | + if (_unityHwnd != IntPtr.Zero) |
36 | 18 | { |
37 | | - int exStyle = GetWindowLong(unityHWND, GWL_EXSTYLE); |
38 | | - SetWindowLong(unityHWND, GWL_EXSTYLE, exStyle | WS_EX_TOOLWINDOW); |
| 19 | + X11Manager.Instance.HideFromTaskbar(); |
39 | 20 | _isHidden = true; |
40 | 21 | } |
41 | 22 | #endif |
42 | 23 | } |
43 | 24 |
|
44 | 25 | public void ToggleAppMode() |
45 | 26 | { |
46 | | -#if UNITY_STANDALONE_WIN && !UNITY_EDITOR |
47 | | - unityHWND = GetUnityWindow(); |
| 27 | +#if UNITY_STANDALONE_WIN && UNITY_EDITOR |
48 | 28 | if (unityHWND == IntPtr.Zero) |
49 | 29 | return; |
50 | 30 |
|
51 | | - int exStyle = GetWindowLong(unityHWND, GWL_EXSTYLE); |
52 | | - |
53 | 31 | if (_isHidden) |
54 | 32 | { |
55 | | - SetWindowLong(unityHWND, GWL_EXSTYLE, exStyle & ~WS_EX_TOOLWINDOW); |
56 | | - ShowWindow(unityHWND, SW_RESTORE); |
57 | | - SetForegroundWindow(unityHWND); |
| 33 | + X11Manager.Instance.HideFromTaskbar(false); |
58 | 34 | _isHidden = false; |
59 | 35 | } |
60 | 36 | else |
61 | 37 | { |
62 | | - SetWindowLong(unityHWND, GWL_EXSTYLE, exStyle | WS_EX_TOOLWINDOW); |
| 38 | + X11Manager.Instance.HideFromTaskbar(); |
63 | 39 | _isHidden = true; |
64 | 40 | } |
65 | 41 | #endif |
66 | 42 | } |
67 | | - |
68 | | - private IntPtr GetUnityWindow() |
69 | | - { |
70 | | - string title = Application.productName; |
71 | | - IntPtr hwnd = FindWindow(null, title); |
72 | | - if (hwnd == IntPtr.Zero) |
73 | | - hwnd = FindWindow("UnityWndClass", null); |
74 | | - return hwnd; |
75 | | - } |
76 | 43 | } |
0 commit comments