You are not logged in.

#1 2008-10-17 19:51:42

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Raw X11 protocol manipulation (below Xlib)

I know this sounds impossible/insane, but I want to see how it's done.

I want to see how to open a socket to X, send data over the wire open the display, initialize and open a window, paint text in it, get events, and so on, without using Xlib or any other helper libraries.

Or is this just too stupid to want to do? tongue

-dav7

Last edited by dav7 (2008-10-18 07:10:05)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#2 2008-10-17 20:17:35

deej
Member
Registered: 2008-02-08
Posts: 395

Re: Raw X11 protocol manipulation (below Xlib)

You are in deep waters, my friend smile
Try here for starters:

http://tronche.com/gui/x/

I've an ebook regarding programming x somewhere; if I find it
I'll let you know.

Deej

Offline

#3 2008-10-17 20:47:08

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Raw X11 protocol manipulation (below Xlib)

It's not too bad, but it does take some boilerplate. It could be more elegant, but I don't know why raw X programming has a reputation for being extremely painful. Here's a little example from Simple Examples of Driving X11 From Common Lisp Using CLX. It opens a window, draws some text, responds to exposure events by redrawing the contents, and closes on a mouse-click event.

(defun hello-world (width height &optional (host ""))
  (let* ((display (xlib:open-display host))
     (screen (first (xlib:display-roots display)))
     (black (xlib:screen-black-pixel screen))
     (white (xlib:screen-white-pixel screen))
     (root-window (xlib:screen-root screen))
     (grackon (xlib:create-gcontext
           :drawable root-window
           :foreground white
           :background black))
     (my-window (xlib:create-window
             :parent root-window
             :x 0
             :y 0
             :width width
             :height height
             :background black
             :event-mask (xlib:make-event-mask :exposure
                               :button-press))))
    (describe (xlib:gcontext-font grackon))
    (xlib:map-window my-window)
    (xlib:event-case (display :force-output-p t
                  :discard-p t)
      (:exposure (count)
     (when (zerop count)
       (xlib:draw-glyphs
         my-window
         grackon
         20 50
         "Hello World!"))
     nil)
      (:button-press () t))
    (xlib:destroy-window my-window)
    (xlib:close-display display)))

EDIT: Although writing window managers is still baffling to me. It would help if there were a clear tutorial that explained just what a WM has to do to do its job. Reading source code leaves one wondering just what is necessary and what is optional.

Last edited by pauldonnelly (2008-10-17 20:49:40)

Offline

#4 2008-10-18 06:46:01

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Raw X11 protocol manipulation (below Xlib)

deej: That looks like an Xlib manual...? hmm

pauldonnely: Ah. That Lisp example is actually an Xlib-based example. Xlib is built on an architecture of binary calls and socket manipulation, and it's the binary area I want to get into; I want to go below Xlib, and see if it really is possible to make an application in less than 40KB because of all the handling you have to do yourself tongue

Also, about windowmanagers, they either implement all or part of the ICCCM, NETWM and EMWH standards or they don't. If they do, they're more awesome than the others tongue (and they have better interoperability)

-dav7

Last edited by dav7 (2008-10-18 06:47:52)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#5 2008-10-18 09:25:15

gnud
Member
Registered: 2005-11-27
Posts: 182

Re: Raw X11 protocol manipulation (below Xlib)

I think it's just stupid smile

Use xcb -- the X protocol c bindings. They are much more barebones than xlib, and also asynchronous, as opposed to the synchronous Xlib.

Offline

#6 2008-10-18 11:44:44

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Raw X11 protocol manipulation (below Xlib)

Interesting. I recently heard about XCB; they might just work out in the future. However, XCB is not everywhere (yet) so isn't admittedly as portable.

-dav7

Last edited by dav7 (2008-10-18 11:45:46)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#7 2008-10-18 22:50:54

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Raw X11 protocol manipulation (below Xlib)

dav7 wrote:

pauldonnely: Ah. That Lisp example is actually an Xlib-based example. Xlib is built on an architecture of binary calls and socket manipulation, and it's the binary area I want to get into; I want to go below Xlib, and see if it really is possible to make an application in less than 40KB because of all the handling you have to do yourself tongue

I totally missed where you said you didn't want to use xlib, and thought you were asking about writing code with xlib rather than a GUI toolkit—which most people consider to be plenty insane.

Offline

#8 2008-10-19 04:26:04

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Raw X11 protocol manipulation (below Xlib)

Heh, I already plan to do that tongue (and am working on such a program at the moment)

The end goal of this is to get enough knowledge about how X works to not only go below Xlib to the socket level but also do it in assembly language. Which I don't really know so well at the moment. tongue

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#9 2008-10-19 06:04:15

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Raw X11 protocol manipulation (below Xlib)

dav7 wrote:

Heh, I already plan to do that tongue (and am working on such a program at the moment)

The end goal of this is to get enough knowledge about how X works to not only go below Xlib to the socket level but also do it in assembly language. Which I don't really know so well at the moment. tongue

-dav7

Sounds like... fun? As long as you realize the badness of this idea for any practical purpose. hmm

Offline

Board footer

Powered by FluxBB