OSDev.org
https://forum.osdev.org/

Implementing the X Server
https://forum.osdev.org/viewtopic.php?f=13&t=56278
Page 1 of 2

Author:  PavelChekov [ Sat May 14, 2022 2:10 pm ]
Post subject:  Implementing the X Server

Does anyone here know of any tutorial/good resources for implementing the X server? Has anyone here done so?

Thanks

Author:  nullplan [ Sat May 14, 2022 2:50 pm ]
Post subject:  Re: Implementing the X Server

Still asking for tutorials? You're not going to be able to do better than the documentation: https://x.org/releases/X11R7.7/doc/xpro ... tocol.html

That's the network protocol. How you turn that into pixels on a screen is up to you. Actually, it is just the core protocol. You might need to implement quite a few extensions also (e.g. you will need Xrender to support many applications using freetype), but the core protocol should be a good starting place.

Author:  PavelChekov [ Sat May 14, 2022 3:04 pm ]
Post subject:  Re: Implementing the X Server

nullplan wrote:
Still asking for tutorials?


I did extensive research and couldn't find anything, so I just asked in case I missed something.

Author:  iansjack [ Sun May 15, 2022 1:59 am ]
Post subject:  Re: Implementing the X Server

Are you looking to implement it from scratch rather than porting it? In the latter case the source code is freely available - in the former you surely wouldn't want to follow a tutorial.

Presumably you have already implemented a TCP/IP stack?

Author:  PavelChekov [ Sun May 15, 2022 10:05 am ]
Post subject:  Re: Implementing the X Server

iansjack wrote:
Are you looking to implement it from scratch rather than porting it? In the latter case the source code is freely available - in the former you surely wouldn't want to follow a tutorial.

Presumably you have already implemented a TCP/IP stack?

I am looking to implement it from scratch, as a sort of learning excercise. My understanding was that the OS provided a network stack.

I am more interested in how X actually goes from XDrawLine to an actual line of pixels on screen.

Author:  nullplan [ Sun May 15, 2022 12:54 pm ]
Post subject:  Re: Implementing the X Server

PavelCheckov wrote:
I did extensive research and couldn't find anything, so I just asked in case I missed something.
You misunderstand. I wasn't asking if you had found any, I was asking why you with your multiple years of OS dev experience had not yet moved on to reading documentation instead of looking for someone else who read it, and then transcribed their understanding into an incomplete and possibly incorrect tutorial.
PavelCheckov wrote:
I am more interested in how X actually goes from XDrawLine to an actual line of pixels on screen.
Bresenham's algorithm, but before you get there, you need a host of other things in place. For example, you need an idea of how to represent your clients in memory (on the frame buffer). X11 is a memory-conservative protocol, and allows the server to get by with remembering pretty much only coordinates of each window, but that is already a computationally interesting proposition. If a foreground window is moved, you need to tell the window that was moved where it was moved to, but you also need to tell all the windows behind it to update their contents. So how do you best determine which windows where behind it? Quadtrees may be a good answer here, but require a lot of thought to use well.

You know, thinking about it, Bresenham's algorithm really is the least of it. You have to deal with different data formats. Some applications get by on monochrome, some need full 32-bit framebuffers with alpha-blending. Some applications use ZPixmaps to render stuff, some use XYPixmaps, so you need to translate data unless you want to go crazy. And you have to provide events (and process reactions to those) in a timely manner. Some of those are more complicated than others.

If you are merely interested in rendering stuff, maybe something like XWayland is more up your alley? Wayland provides the frame buffer and events, XWayland merely translates from one to the other. And Wayland doesn't handle rendering, it tells lets the client do it and expects to be told to just update the window contents.

Author:  PavelChekov [ Sun May 15, 2022 12:58 pm ]
Post subject:  Re: Implementing the X Server

nullplan wrote:
You misunderstand. I wasn't asking if you had found any, I was asking why you with your multiple years of OS dev experience had not yet moved on to reading documentation instead of looking for someone else who read it, and then transcribed their understanding into an incomplete and possibly incorrect tutorial.

It would still save me quite a bit of time in understanding the basics.
nullplan wrote:
Bresenham's algorithm

I figured that much out, I was more referring to actually displaying the pixel on the screen.

Author:  thewrongchristian [ Sun May 15, 2022 3:04 pm ]
Post subject:  Re: Implementing the X Server

A quick search for "windowing system tutorial" brings up:


Might be a good start.

And/or, you could compile up Xnest, and run it under a debugger on an existing desktop, and trace the code from network input to writing to the virtual (nested) screen.

Author:  davmac314 [ Sun May 15, 2022 8:19 pm ]
Post subject:  Re: Implementing the X Server

PavelCheckov wrote:
I figured that much out, I was more referring to actually displaying the pixel on the screen.

You probably should've started with that as your question; it can get frustrating when people ask broad questions like "how to implement an X server" because there is no simple answer and it is unclear at what level the question is aimed. (You have a bit of a history of asking such questions; I don't think you realise how frustrating it can be). If you ask the right question to begin with, it's better for everyone.

With that said, on Linux for instance this can be done via the framebuffer device (documentation is available, but not very comprehensive. I suggest searching for a examples).

Author:  PavelChekov [ Mon May 16, 2022 7:20 am ]
Post subject:  Re: Implementing the X Server

davmac314 wrote:
PavelCheckov wrote:
I figured that much out, I was more referring to actually displaying the pixel on the screen.

You probably should've started with that as your question; it can get frustrating when people ask broad questions like "how to implement an X server" because there is no simple answer and it is unclear at what level the question is aimed. (You have a bit of a history of asking such questions; I don't think you realise how frustrating it can be). If you ask the right question to begin with, it's better for everyone.

With that said, on Linux for instance this can be done via the framebuffer device (documentation is available, but not very comprehensive. I suggest searching for a examples).

Thank you, I will keep that in mind when asking future questions. I apologize.

Author:  Ringding [ Tue May 17, 2022 1:02 am ]
Post subject:  Re: Implementing the X Server

I doubt that anyone was crazy enough to implement an X server during the last 3 decades, even large corporations. Everyone would just fork the Xorg code. I will likely be proven wrong quickly, but the point is that this would be a monstrous undertaking that you probably don’t want to get yourself into.

Author:  klange [ Tue May 17, 2022 3:46 am ]
Post subject:  Re: Implementing the X Server

davmac314 wrote:
You probably should've started with that as your question; it can get frustrating when people ask broad questions like "how to implement an X server" because there is no simple answer and it is unclear at what level the question is aimed. (You have a bit of a history of asking such questions; I don't think you realise how frustrating it can be). If you ask the right question to begin with, it's better for everyone.

Classic case of an x-y problem.

Ringding wrote:
I doubt that anyone was crazy enough to implement an X server during the last 3 decades, even large corporations. Everyone would just fork the Xorg code. I will likely be proven wrong quickly, but the point is that this would be a monstrous undertaking that you probably don’t want to get yourself into.

The closest I can think of is that someone implemented an Xlib compatibility layer for Haiku. They skipped the "build an X server" part by translating Xlib calls to Haiku's graphics API.

Author:  Voldemort [ Thu Aug 18, 2022 10:23 am ]
Post subject:  Re: Implementing the X Server

Hi Pavel,

This seems like a well documented project which might help you in your quest.

https://github.com/ghaerr/microwindows

Author:  PavelChekov [ Thu Aug 18, 2022 4:40 pm ]
Post subject:  Re: Implementing the X Server

Voldemort wrote:
Hi Pavel,

This seems like a well documented project which might help you in your quest.

https://github.com/ghaerr/microwindows


Thanks! Also, I noticed people referring to me as "Pavel", which I just want to put on the record is my username based on Checkov from Star Trek, because some people on here have assumed I'm Russian and that I don't speak English, neither of which are true (Slava Ukraini!).

Author:  klange [ Thu Aug 18, 2022 5:15 pm ]
Post subject:  Re: Implementing the X Server

PavelCheckov wrote:
Thanks! Also, I noticed people referring to me as "Pavel", which I just want to put on the record is my username based on Checkov from Star Trek

If you style yourself after a character, you should expect as much, Mr. Checkov. Do you know where I can find any nuclear wessels?


(btw your name is spelled wrong, it should be Chekov!)

Page 1 of 2 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/