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 Dec 14, 2024
1 parent dc5f1b7 commit 1cea0a3
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 @@ -2145,7 +2145,11 @@
[b]Note:[/b] This flag is implemented on macOS and Windows.
[b]Note:[/b] Setting this flag will [b]NOT[/b] prevent other apps from capturing an image, it should not be used as a security measure.
</constant>
<constant name="WINDOW_FLAG_MAX" value="10" enum="WindowFlags">
<constant name="WINDOW_FLAG_SKIP_TASKBAR" value="10" 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="11" 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 @@ -670,6 +670,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 @@ -861,7 +866,12 @@
[b]Note:[/b] This flag is implemented on macOS and Windows.
[b]Note:[/b] Setting this flag will [b]NOT[/b] prevent other apps from capturing an image, it should not be used as a security measure.
</constant>
<constant name="FLAG_MAX" value="10" enum="Flags">
<constant name="FLAG_SKIP_TASKBAR" value="10" 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="11" 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 @@ -2461,6 +2461,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 @@ -1557,6 +1557,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 @@ -2491,6 +2494,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 @@ -2529,6 +2548,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 @@ -5988,6 +6010,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 @@ -490,6 +490,7 @@ class DisplayServerWindows : public DisplayServer {
bool mpass = false;
bool sharp_corners = false;
bool hide_from_capture = 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 @@ -3009,6 +3009,7 @@ void Window::_bind_methods() {
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, "exclude_from_capture"), "set_flag", "get_flag", FLAG_EXCLUDE_FROM_CAPTURE);
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 @@ -3064,6 +3065,7 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(FLAG_SHARP_CORNERS);
BIND_ENUM_CONSTANT(FLAG_EXCLUDE_FROM_CAPTURE);
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 @@ -65,6 +65,7 @@ class Window : public Viewport {
FLAG_MOUSE_PASSTHROUGH = DisplayServer::WINDOW_FLAG_MOUSE_PASSTHROUGH,
FLAG_SHARP_CORNERS = DisplayServer::WINDOW_FLAG_SHARP_CORNERS,
FLAG_EXCLUDE_FROM_CAPTURE = DisplayServer::WINDOW_FLAG_EXCLUDE_FROM_CAPTURE,
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 @@ -1141,6 +1141,7 @@ void DisplayServer::_bind_methods() {
BIND_ENUM_CONSTANT(WINDOW_FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(WINDOW_FLAG_SHARP_CORNERS);
BIND_ENUM_CONSTANT(WINDOW_FLAG_EXCLUDE_FROM_CAPTURE);
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 @@ -390,6 +390,7 @@ class DisplayServer : public Object {
WINDOW_FLAG_MOUSE_PASSTHROUGH,
WINDOW_FLAG_SHARP_CORNERS,
WINDOW_FLAG_EXCLUDE_FROM_CAPTURE,
WINDOW_FLAG_SKIP_TASKBAR,
WINDOW_FLAG_MAX,
};

Expand All @@ -405,6 +406,7 @@ class DisplayServer : public Object {
WINDOW_FLAG_MOUSE_PASSTHROUGH_BIT = (1 << WINDOW_FLAG_MOUSE_PASSTHROUGH),
WINDOW_FLAG_SHARP_CORNERS_BIT = (1 << WINDOW_FLAG_SHARP_CORNERS),
WINDOW_FLAG_EXCLUDE_FROM_CAPTURE_BIT = (1 << WINDOW_FLAG_EXCLUDE_FROM_CAPTURE),
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 1cea0a3

Please sign in to comment.