Skip to content

Commit

Permalink
Add functionality to hide windows from taskbar (Windows only).
Browse files Browse the repository at this point in the history
  • Loading branch information
Lielay9 committed Nov 30, 2024
1 parent 893bbdf commit 2087f9b
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("display/window/size/extend_to_title", false);
GLOBAL_DEF("display/window/size/no_focus", false);
GLOBAL_DEF("display/window/size/sharp_corners", false);
GLOBAL_DEF("display/window/size/skip_taskbar", false);

GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
Expand Down
6 changes: 5 additions & 1 deletion doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,11 @@
Window style is overridden, forcing sharp corners.
[b]Note:[/b] This flag is implemented only on Windows (11).
</constant>
<constant name="WINDOW_FLAG_MAX" value="9" enum="WindowFlags">
<constant name="WINDOW_FLAG_SKIP_TASKBAR" value="9" enum="WindowFlags">
Window won't be visible in the taskbar or in the system's window manager's window list.
[b]Note:[/b] This flag is implemented only on Windows.
</constant>
<constant name="WINDOW_FLAG_MAX" value="10" enum="WindowFlags">
Max value of the [enum WindowFlags].
</constant>
<constant name="WINDOW_EVENT_MOUSE_ENTER" value="0" enum="WindowEvent">
Expand Down
4 changes: 4 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,10 @@
If [code]true[/code], the main window uses sharp corners by default.
[b]Note:[/b] This property is implemented only on Windows (11).
</member>
<member name="display/window/size/skip_taskbar" type="bool" setter="" getter="" default="false">
If [code]true[/code], the main window won't be visible in the taskbar or in the system's window manager's window list.
[b]Note:[/b] This property is implemented only on Windows.
</member>
<member name="display/window/size/transparent" type="bool" setter="" getter="" default="false">
If [code]true[/code], enables a window manager hint that the main window background [i]can[/i] be transparent. This does not make the background actually transparent. For the background to be transparent, the root viewport must also be made transparent by enabling [member rendering/viewport/transparent_background].
[b]Note:[/b] To use a transparent splash screen, set [member application/boot_splash/bg_color] to [code]Color(0, 0, 0, 0)[/code].
Expand Down
12 changes: 11 additions & 1 deletion doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@
<member name="size" type="Vector2i" setter="set_size" getter="get_size" default="Vector2i(100, 100)">
The window's size in pixels.
</member>
<member name="skip_taskbar" type="bool" setter="set_flag" getter="get_flag" default="false">
If [code]true[/code], the [Window] won't be visible in the taskbar or in the system's window manager's window list.
[b]Note:[/b] This property is implemented only on Windows.
[b]Note:[/b] This property only works with native windows.
</member>
<member name="theme" type="Theme" setter="set_theme" getter="get_theme">
The [Theme] resource this node and all its [Control] and [Window] children use. If a child node has its own [Theme] resource set, theme items are merged with child's definitions having higher priority.
[b]Note:[/b] [Window] styles will have no effect unless the window is embedded.
Expand Down Expand Up @@ -853,7 +858,12 @@
[b]Note:[/b] This flag has no effect in embedded windows.
[b]Note:[/b] This flag is implemented only on Windows (11).
</constant>
<constant name="FLAG_MAX" value="9" enum="Flags">
<constant name="FLAG_SKIP_TASKBAR" value="9" enum="Flags">
Window won't be visible in the taskbar or in the system's window manager's window list.
[b]Note:[/b] This flag has no effect in embedded windows.
[b]Note:[/b] This flag is implemented only on Windows.
</constant>
<constant name="FLAG_MAX" value="10" enum="Flags">
Max value of the [enum Flags].
</constant>
<constant name="CONTENT_SCALE_MODE_DISABLED" value="0" enum="ContentScaleMode">
Expand Down
3 changes: 3 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (bool(GLOBAL_GET("display/window/size/sharp_corners"))) {
window_flags |= DisplayServer::WINDOW_FLAG_SHARP_CORNERS_BIT;
}
if (bool(GLOBAL_GET("display/window/size/skip_taskbar"))) {
window_flags |= DisplayServer::WINDOW_FLAG_SKIP_TASKBAR_BIT;
}
window_mode = (DisplayServer::WindowMode)(GLOBAL_GET("display/window/size/mode").operator int());
int initial_position_type = GLOBAL_GET("display/window/size/initial_position_type").operator int();
if (initial_position_type == 0) { // Absolute.
Expand Down
32 changes: 32 additions & 0 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,9 @@ DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mod
if (p_flags & WINDOW_FLAG_SHARP_CORNERS_BIT) {
wd.sharp_corners = true;
}
if (p_flags & WINDOW_FLAG_SKIP_TASKBAR_BIT) {
wd.skip_taskbar = true;
}
if (p_flags & WINDOW_FLAG_NO_FOCUS_BIT) {
wd.no_focus = true;
}
Expand Down Expand Up @@ -2389,6 +2392,22 @@ void DisplayServerWindows::window_set_flag(WindowFlags p_flag, bool p_enabled, W
ERR_FAIL_COND_MSG(IsWindowVisible(wd.hWnd) && (wd.is_popup != p_enabled), "Popup flag can't changed while window is opened.");
wd.is_popup = p_enabled;
} break;
case WINDOW_FLAG_SKIP_TASKBAR: {
if (wd.skip_taskbar != p_enabled) {
wd.skip_taskbar = p_enabled;
ITaskbarList *tbl = nullptr;
if (SUCCEEDED(CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList, (LPVOID *)&tbl))) {
if (SUCCEEDED(tbl->HrInit())) {
if (p_enabled) {
tbl->DeleteTab(wd.hWnd);
} else {
tbl->AddTab(wd.hWnd);
}
}
SAFE_RELEASE(tbl)
}
}
} break;
default:
break;
}
Expand Down Expand Up @@ -2421,6 +2440,9 @@ bool DisplayServerWindows::window_get_flag(WindowFlags p_flag, WindowID p_window
case WINDOW_FLAG_POPUP: {
return wd.is_popup;
} break;
case WINDOW_FLAG_SKIP_TASKBAR: {
return wd.skip_taskbar;
} break;
default:
break;
}
Expand Down Expand Up @@ -5852,6 +5874,16 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
SetWindowPos(wd.hWnd, HWND_TOP, srect.position.x, srect.position.y, srect.size.width, srect.size.height, SWP_NOZORDER | SWP_NOACTIVATE);
}

if (p_flags & WINDOW_FLAG_SKIP_TASKBAR_BIT) {
ITaskbarList *tbl = nullptr;
if (SUCCEEDED(CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList, (LPVOID *)&tbl))) {
if (SUCCEEDED(tbl->HrInit())) {
tbl->DeleteTab(wd.hWnd);
}
SAFE_RELEASE(tbl)
}
}

wd.create_completed = true;
window_id_counter++;
}
Expand Down
1 change: 1 addition & 0 deletions platform/windows/display_server_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ class DisplayServerWindows : public DisplayServer {
bool context_created = false;
bool mpass = false;
bool sharp_corners = false;
bool skip_taskbar = false;

// Used to transfer data between events using timer.
WPARAM saved_wparam;
Expand Down
2 changes: 2 additions & 0 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,7 @@ void Window::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "extend_to_title"), "set_flag", "get_flag", FLAG_EXTEND_TO_TITLE);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "mouse_passthrough"), "set_flag", "get_flag", FLAG_MOUSE_PASSTHROUGH);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "sharp_corners"), "set_flag", "get_flag", FLAG_SHARP_CORNERS);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "skip_taskbar"), "set_flag", "get_flag", FLAG_SKIP_TASKBAR);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_native"), "set_force_native", "get_force_native");

ADD_GROUP("Limits", "");
Expand Down Expand Up @@ -3044,6 +3045,7 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_EXTEND_TO_TITLE);
BIND_ENUM_CONSTANT(FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(FLAG_SHARP_CORNERS);
BIND_ENUM_CONSTANT(FLAG_SKIP_TASKBAR);
BIND_ENUM_CONSTANT(FLAG_MAX);

BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED);
Expand Down
1 change: 1 addition & 0 deletions scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Window : public Viewport {
FLAG_EXTEND_TO_TITLE = DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE,
FLAG_MOUSE_PASSTHROUGH = DisplayServer::WINDOW_FLAG_MOUSE_PASSTHROUGH,
FLAG_SHARP_CORNERS = DisplayServer::WINDOW_FLAG_SHARP_CORNERS,
FLAG_SKIP_TASKBAR = DisplayServer::WINDOW_FLAG_SKIP_TASKBAR,
FLAG_MAX = DisplayServer::WINDOW_FLAG_MAX,
};

Expand Down
1 change: 1 addition & 0 deletions servers/display_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ void DisplayServer::_bind_methods() {
BIND_ENUM_CONSTANT(WINDOW_FLAG_EXTEND_TO_TITLE);
BIND_ENUM_CONSTANT(WINDOW_FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(WINDOW_FLAG_SHARP_CORNERS);
BIND_ENUM_CONSTANT(WINDOW_FLAG_SKIP_TASKBAR);
BIND_ENUM_CONSTANT(WINDOW_FLAG_MAX);

BIND_ENUM_CONSTANT(WINDOW_EVENT_MOUSE_ENTER);
Expand Down
2 changes: 2 additions & 0 deletions servers/display_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class DisplayServer : public Object {
WINDOW_FLAG_EXTEND_TO_TITLE,
WINDOW_FLAG_MOUSE_PASSTHROUGH,
WINDOW_FLAG_SHARP_CORNERS,
WINDOW_FLAG_SKIP_TASKBAR,
WINDOW_FLAG_MAX,
};

Expand All @@ -400,6 +401,7 @@ class DisplayServer : public Object {
WINDOW_FLAG_EXTEND_TO_TITLE_BIT = (1 << WINDOW_FLAG_EXTEND_TO_TITLE),
WINDOW_FLAG_MOUSE_PASSTHROUGH_BIT = (1 << WINDOW_FLAG_MOUSE_PASSTHROUGH),
WINDOW_FLAG_SHARP_CORNERS_BIT = (1 << WINDOW_FLAG_SHARP_CORNERS),
WINDOW_FLAG_SKIP_TASKBAR_BIT = (1 << WINDOW_FLAG_SKIP_TASKBAR),
};

virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i(), bool p_exclusive = false, WindowID p_transient_parent = INVALID_WINDOW_ID);
Expand Down

0 comments on commit 2087f9b

Please sign in to comment.