valinet / Win11DisableRoundedCorners

A simple utility that cold patches dwm (uDWM.dll) in order to disable window rounded corners in Windows 11
GNU General Public License v2.0
828 stars 41 forks source link

Easiest way to disable rounded corners (no patching/adapter required) #42

Open limacohen opened 1 year ago

limacohen commented 1 year ago

I stumbled across this preference in PowerToys. If you just want to disable rounded corners and you don't mind using FancyZones, this is by far the easiest (official?) way to do it: "Disable round corners when window is snapped"

oberrich commented 1 year ago

Interesting, looks like it's possible to set this on a per-window basis using DwmSetWindowAttribute + DWM_WINDOW_CORNER_PREFERENCE.

I wonder if this could get rid of the need for running with elevation. One minor issue I see with this method is the need to install a window hook or have a thread polling to account for new windows. This is also only (officially) supported starting with build 22000.

valinet commented 1 year ago

Interesting, looks like it's possible to set this on a per-window basis using DwmSetWindowAttribute + DWM_WINDOW_CORNER_PREFERENCE.

I wonder if this could get rid of the need for running with elevation. One minor issue I see with this method is the need to install a window hook or have a thread polling to account for new windows.

You cannot get around elevation. As a principle, an app cannot “alter” another app which is on a higher privilege level.

ExplorerPatcher already uses this API for Simple Windows Switcher’s “corner” preference.

The thing with this API is that making use of it reliably is more cumbersome:

  1. To modify elevated apps, you need to run elevated.
  2. You need a global hook on window creation, something like a shell hook and looking for the HSHELL_RUDEAPPACTIVATED or HSHELL_WINDOWACTIVATED. Maybe additionally a “winevent” hook… the strategy used by sws can be used and can detect new windows that are created and alter them.
  3. Of course, apps can still override what you do, this largely being a hack.
  4. There may be trouble altering protected processes or protected processes light, and no real solution might be there other than creating a service…
  5. It might be more reliable to continuously poll the window list and set the property on all windows, but or course this consumes tons of resources for nothing really. Even with a hook, it consumes more compared to previous, well established methods.
  6. With the method employed by ep_dwm or win11-toggle-rounded-corners, for example, it’s just is more reliable and always respected: the compositor is forced to always draw right angle corners, so all windows are affected.

So yeah, idk, I wouldn’t call this easy at all. The method employed by ep_dwm (ExplorerPatcher) is the technically correct strategy. Rounded corners appeared only since around build 22000, so I don’t see the problem here - this API works basically since Windows 11 RTM, like the Mica backdrop brush and so on.

limacohen commented 1 year ago

So yeah, idk, I wouldn’t call this easy at all.

I mean, it's easy from the user point of view. I already use FancyZones so I just had to click a checkbox. I'm sure this would be the case for other people too. I assume the window hook was already in place for moving/resizing the windows.

Just to be clear, I enormously appreciate the effort done by both of you guys. I'm just shedding some light into an alternative way to get to the same(ish) thing.

valinet commented 1 year ago

So yeah, idk, I wouldn’t call this easy at all.

I mean, it's easy from the user point of view. I already use FancyZones so I just had to click a checkbox. I'm sure this would be the case for other people too. I assume the window hook was already in place for moving/resizing the windows.

Just to be clear, I enormously appreciate the effort done by both of you guys. I'm just shedding some light into an alternative way to get to the same(ish) thing.

Yeah, idk, as I said, no doubt it can work. Everybody can decide what works best for them. I looked on FancyZones: the fact that it is a first party product yet it employs so many hacks against their own operating system says a lot about how friendly developing on Windows has become.

As I said, it probably runs some elevated agent in order to apply the property to elevated windows. Do PowerToys require admin when installing…?

oberrich commented 1 year ago

I agree that this method does require more work to get working perfectly and it's not really worth the effort.

You cannot get around elevation. As a principle, an app cannot “alter” another app which is on a higher privilege level.

Well you can get a window handle to every process without elevation, that's what motivated my thinking here. Taking a quick glance at DwmSetWindowAttribute there is some access checks happening in win32k, cba to look into it any further though.

As I said, it probably runs some elevated agent in order to apply the property to elevated windows. Do PowerToys require admin when installing…?

The installer seems to schedule an elevated task. Being MSFT they could even digitally sign using Windows Publisher and casually bypass UAC prompts (autoElevate) if they chose to. I think it's quite sad that just wanting to install an app to be run as admin is such a hassle on this platform.