Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Remove title bars from windows #504

Closed
FrancisTheCat opened this issue Jan 9, 2024 · 6 comments · Fixed by #735
Closed

[Feature Request] Remove title bars from windows #504

FrancisTheCat opened this issue Jan 9, 2024 · 6 comments · Fixed by #735
Labels

Comments

@FrancisTheCat
Copy link

I think most people that use a wm dont like these annoying white bars, but you cant really turn them of, or can you (without just removing all decorations icluding the rounded corners)? I managed to write some Odin code to get rid of the on the few apps that I use that actually have them, however it would be really convenient to have this be feature of glaze, wich is a really good wm btw, big thanks to everyone who participates in this project. Anyway here is my code, you could probably use it as a starting point for a c# implemenation, or maybe this at least helps someone out. I would implement this myself, but Im just not good at c#.
Further reading:

package title_remover

import "core:fmt"
import "core:os"
import "core:runtime"
import "core:slice"
import "core:strings"

import win "core:sys/windows"

// if any title _CONTAINS_ one of these strings it will get its borders removed
MANAGE :: []string{"CactusViewer", "Minecraft"}

enum_windows_proc :: proc "stdcall" (hWnd: win.HWND, lParam: win.LPARAM) -> win.BOOL {
	context = runtime.default_context()

	handles := transmute(^[dynamic]win.HWND)lParam
	append(handles, hWnd)

	return true
}

main :: proc() {
	handles := make([dynamic]win.HWND)
	win.EnumWindows(enum_windows_proc, transmute(win.LPARAM)&handles)

	for handle in handles {
		str := make([]u16, 1024)

		n := win.GetWindowTextW(handle, raw_data(str), 1023)

		manageable := true

		title, _ := win.utf16_to_utf8(str[:n])

		if manageable {
			for m in MANAGE {
				if strings.contains(title, m) {
					remove_window_title_bar(handle)
					break
				}
			}
		}

	}
}

remove_window_title_bar :: proc(hWnd: win.HWND) -> bool {
	if hWnd == nil {
		return false
	}

	preference: i32 = 2
	result := win.DwmSetWindowAttribute(
		hWnd,
		auto_cast win.DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE,
		&preference,
		size_of(preference),
	)

	return(
		win.SUCCEEDED(result) &&
		win.SetWindowLongW(hWnd, win.GWL_STYLE, transmute(i32)win.WS_POPUPWINDOW) != 0 \
	)
}

PS: command: "resize borders 0px -7px -7px -7px", as a window rule in your config fixes the size of most windows without titlebars

@FrancisTheCat
Copy link
Author

Got a kind of working solution! I packaged the above code into a somewhat useable cli app that you can use to remove titles from windows matching some title, classname or executable file name. I can now set an exec command and everything would work, if the args stayed lowercase. So I removed to .ToLowerInvariants() in the command parsing code, however I dont think thats a particularly good solution, because its still kind of hacky.

  - command: "exec 'Path/to/title_remover.exe' title regex Minecraft.*"
    match_title: "Minecraft.*"

@FrancisTheCat
Copy link
Author

This is the result btw:

old:

image

new:

image

@FrancisTheCat FrancisTheCat changed the title Remove title bars from windows [Feature Request] Remove title bars from windows Jan 10, 2024
@FrancisTheCat
Copy link
Author

Going to close this once this pr gets merged: #528

@JonasWischeropp
Copy link
Contributor

I have created a new PR #735.
Thank you @FrancisTheCat for your work. It helped alot to implement it.

@FrancisTheCat
Copy link
Author

I have created a new PR #735. Thank you @FrancisTheCat for your work. It helped alot to implement it.

Oh that's nice, glad to know it was useful to you

Copy link

github-actions bot commented Oct 1, 2024

🎉 This issue has been resolved in version 3.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants