I made OneOS before the window API was released, so I've never really used it. Personally, what I've done is downloaded the ComputerCraft jar file and extracted it (just rename it to a .zip) then taken the Lua code out. This allows you to easily see how the APIs work and also helps immensely when sandboxing or customising functions (such as making your own os.loadAPI function).
If you're making an OS I'd also make sure you try and modularise everything if you can. When you have a program such as OneOS you just can't put all of it in one file, last time I checked it was about 20 thousand lines. It allows you to swap things around easier and make things quicker. You should also use a centralised drawing API, using term.write is just tacky and it also allows you to have buffers, do things like clipping, colour blending and draw blocks of colour with a single line rather than using a 10 or so line for loop.
You could also take a look at
Bedrock, it’s got quite a special and specific way of doing things and takes a bit to learn, but it makes creating powerful GUIs really easy. It’s completely different from standard ComptuerCraft programming though.
To answer your question about windows though. I like doing an object oriented model, I think it’s a cleaner and easier way to do things, but it’s just my personal preference. So what I would do is create an object for a window container. You’d have properties such as the X, Y, width, height, title, etc. You’d also set the window API object. Using your click detection code, I’d then send the click event to the window container, if Y == 1 then you set another property, called something like “DragX” and you’d set this property to the X value (relative to the window) of the click event. You’d then start a timer of about a second and set the returned number to some variable. When the timer event fires you then set this variable to nil. Now any mouse_drag events you receive while that timer is not nil should be assumed to be a window drag. When this happens you restart the timer and move the window to the drag location minus the DragX value so the cursor position stays in the same place.
It’s a bit of a long winded explanation, but it’s pretty much exactly what I did with
PearOS windows. Maybe take a look at the code for that on GitHub. I don’t actually think I have any window dragging in OneOS, but because it uses Bedrock it’s a bit more obscure to learn from.