Skip to content

Commit 8c6be78

Browse files
Removed taskbar (dock) icon
1 parent 4cd68df commit 8c6be78

2 files changed

Lines changed: 37 additions & 42 deletions

File tree

Assets/MATE ENGINE - Scripts/APIs/X11Manager.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,34 @@ public void SetTopmost(bool topmost = true)
359359
XSendEvent(_display, _rootWindow, false, 0x00100000 | 0x00080000, ref xClient);
360360
XFlush(_display);
361361
}
362+
363+
public void HideFromTaskbar(bool reallyHide = true)
364+
{
365+
IntPtr netWmState = XInternAtom(_display, "_NET_WM_STATE", false);
366+
IntPtr skipTaskbar = XInternAtom(_display, "_NET_WM_STATE_SKIP_TASKBAR", false);
367+
368+
if (netWmState == IntPtr.Zero || skipTaskbar == IntPtr.Zero)
369+
return;
370+
371+
XClientMessageEvent msg = new()
372+
{
373+
type = 33, // ClientMessage
374+
display = _display,
375+
window = _unityWindow,
376+
message_type = netWmState,
377+
format = 32,
378+
data = new IntPtr[5]
379+
};
380+
msg.data[0] = new(reallyHide ? 1 : 0);
381+
msg.data[1] = skipTaskbar;
382+
msg.data[2] = IntPtr.Zero;
383+
msg.data[3] = IntPtr.Zero;
384+
msg.data[4] = new(1);
385+
386+
XSendEvent(_display, _rootWindow, false, 0x10000L | 0x20000L, ref msg);
387+
XFlush(_display);
388+
}
389+
362390

363391
private void SetWindowBorderless()
364392
{
Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,43 @@
11
using System;
2-
using System.Runtime.InteropServices;
32
using UnityEngine;
3+
using X11;
44

55
public class RemoveTaskbarApp : MonoBehaviour
66
{
7-
[DllImport("user32.dll", SetLastError = true)]
8-
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
97

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;
279

2810
private bool _isHidden = true;
2911
public bool IsHidden => _isHidden;
3012

3113
void Start()
3214
{
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)
3618
{
37-
int exStyle = GetWindowLong(unityHWND, GWL_EXSTYLE);
38-
SetWindowLong(unityHWND, GWL_EXSTYLE, exStyle | WS_EX_TOOLWINDOW);
19+
X11Manager.Instance.HideFromTaskbar();
3920
_isHidden = true;
4021
}
4122
#endif
4223
}
4324

4425
public void ToggleAppMode()
4526
{
46-
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
47-
unityHWND = GetUnityWindow();
27+
#if UNITY_STANDALONE_WIN && UNITY_EDITOR
4828
if (unityHWND == IntPtr.Zero)
4929
return;
5030

51-
int exStyle = GetWindowLong(unityHWND, GWL_EXSTYLE);
52-
5331
if (_isHidden)
5432
{
55-
SetWindowLong(unityHWND, GWL_EXSTYLE, exStyle & ~WS_EX_TOOLWINDOW);
56-
ShowWindow(unityHWND, SW_RESTORE);
57-
SetForegroundWindow(unityHWND);
33+
X11Manager.Instance.HideFromTaskbar(false);
5834
_isHidden = false;
5935
}
6036
else
6137
{
62-
SetWindowLong(unityHWND, GWL_EXSTYLE, exStyle | WS_EX_TOOLWINDOW);
38+
X11Manager.Instance.HideFromTaskbar();
6339
_isHidden = true;
6440
}
6541
#endif
6642
}
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-
}
7643
}

0 commit comments

Comments
 (0)