How to keep an object constant in screen space? If you open the modern Blender UI and select for example scaling, and then you use the scroll wheel to "zoom" (move the camera along the radial axis). You will notice that the size of the 3D
widget remains constant in screen space (it becomes bigger or smaller in regards to all the other objects).

I am wondering how this can be achieved. I assume there is an obvious matrix cancellation you can do, e.g setting the w component to 1 after projecting. But I am not sure.

As you can see the widget's size in screen space is identical:
Scale the object proportional to its depth (z in camera space) and it will retain the same size on screen regardless of its position in world space.

Additionally, you might also wish to scale the object proportional to the field of view so that it retains the same screen size regardless of the camera zoom. (Specifically, scale it by tan(fov/2)).

Finally, you might also wish to scale it inversely proportional to the pixel size of the window if you want the widget to retain a constant size in pixels regardless of how large the window is. Otherwise it will be constant as a fraction of the window size.

I wouldn't recommend trying to do this in post-projective space (by manipulating w, etc) because it will scale the object's distance from the camera at the same time as scaling its size. Effectively you're scaling it in camera space. What you really want to do is scale it in its own local space before applying world-view-projection transformations.