user36457
user36457

Reputation:

How do you make linux GUI's?

My main experience is with C && C++, so I'd prefer to remain with them. I don't want to use anything like QT, GTK, or wxWidgets or any tool kits. I'd like to learn native programming and this sort of defeats the purpose. With that in mind I'd also like to avoid Java.

I understand gnome and xfce and KDE and such are all Desktop Environments for Linux, and the base installed typically is X (Xorg). When coding for Linux, do you code for X, or for the desktop environment? Is there a standard Linux header for this (like win32 has windows.h) for Linux? or is it different coding methods for every desktop environment?

any help is greatly appreciated.

Upvotes: 27

Views: 18626

Answers (12)

Calmarius
Calmarius

Reputation: 19451

The problem is that Linux the GUI is incredibly fragmented, even more fragmented than before. There are a bunch of desktop environments and window managers, each do the same things in a different way.

Historically each of these things talked with the X server, which was a common denominator for them. You can use the X protocol to create a window. It's nothing just a rectangular area you can draw into and receive mouse and keyboard events from. Everything else was the job of the desktop environment, so if you wanted widgets, notifications, tray icons, etc. you needed to talk with the desktop environment.

If you want to be able to ask the user if they really want to exit when they hit the close window button, you need to talk with the window manager to arrange what should happen when the user closes the window, by default most window managers just disconnect the client program from the X server and destroy its windows.

So you need code that's specific to each window manager and each desktop environment.

Nowadays even X is deprecated and is being replaced by Wayland gradually. Wayland is so stripped down that doesn't know how to create a window, as it's done by the compositor and there are many of them. So if you want to make a window there, you need to write code for each specific compositor.

So GUI is even more fragmented on Linux nowadays.

The situation is similar what we have/had in web development where each browser behaves differently so a framework is needed to bridge the differences between them.

For this same reason you need to use a GUI framework so you don't need to bother with the differences between the windows managers and desktop environments.

If you don't want interact with the environment, and you just want a window and draw stuff into it then X protocol is enough, but you will hit the wall pretty early.

Upvotes: 0

plan9assembler
plan9assembler

Reputation: 2984

oh yeah, there is such "native" things:

FBUI, svgalib, directfb, exa(kdrive), SDL, Allegro..+Wayland, although not mainstream.

http://home.comcast.net/~fbui/

http://www.svgalib.org/

http://directfb.org/

http://xorg.freedesktop.org/wiki/ExaStatus

+ http://wayland.freedesktop.org/

Upvotes: 1

Nicola Musatti
Nicola Musatti

Reputation: 18236

Why not choose one among, say, Qt, wxWidgets and GTK and learn its internals, rather than its API? I do not mean just for the sake of it, but with the aim of contributing to the parts you find most appealing. In this way you'd fulfill your goal and get to do something useful, for you and also for others. I think this would be more rewarding than assigning yourself the rather artificial task of building an application with what amount to the wrong tools.

Upvotes: 0

luser droog
luser droog

Reputation: 19514

I feel it necessary to counterpoint the unanimity of the other answers here. X11 is indeed low level. But to "truly" understand what's going on, you should have some familiarity with how X11 works. Since all the toolkits work on top of X, you're using it whether you like it or not. There is nice tutorial online somewhere that I'm too lazy to search for. It guides you through building a simple Hello World. To do it, you'll have to learn how to create a window, request events, map the window, and process events in a loop. You could even go so far as to order some used books on Amazon. The O'Reilly vols 1 and 2 (for now get the cheapest editions, but nothing earlier than X11R4) are essential for reference and to get the full story of how the pieces work together. For learning, however, the best book is X Window Applications Programming by Eric Johnson and Kevin Reichard.

At some point along this journey, as everyone else says, you will find you've had enough. Two pages of code just to select a visual, and then you still have to populate a colormap before you can paint your custom bitmap. And then two days of rewriting and debugging to realize that it all does work; you just forgot to XFlush()!

The struggle is important, because you'll appreciate the toolkits more once you find the one you like.

Upvotes: 5

paxdiablo
paxdiablo

Reputation: 882386

X is a hideous layer to program for and, despite your intent to avoid Java, QT or any of the excellent UI abstraction layers, you'll be doing yourself a disservice by coding to that level. I've done it (a long time ago when Motif was in its infancy on the platform we were using) and I would not do it again if there was an easier way.

Your use of the phrase "native programming" confuses me a little. If you want to learn native programming, it's to the APIs that you choose to call. Using similar reasoning, you shouldn't be coding in C either, instead opting for assembler (or direct machine code) since C provides an abstraction to the hardware.

If you want to learn X programming, that's fine. You'll end up with a lot more control over your interface but almost everyone else will be out-performing you in terms of delivery of software. Myself, I'd prefer to code to a higher-level API that I can use on many platforms - it gives me both faster delivery times and more market potential.

You don't build a house out of atoms, you build it out of bricks. My suggestion is to use the tools, that's what they're there for.

Upvotes: 69

shash
shash

Reputation: 975

Unix (and by extension, Linux) doesn't actually define anything to do with GUIs. X, which is commonly used, doesn't define anything to do with widgets or styles or anything of that nature - it's concerned mostly with drawing primitives and event handling. Essentially, if you wanted to write in pure X, you'd be defining the shape and behaviour of every element on screen. If you were crazy enough to abandon X, you'd be working at the graphics framebuffer level...

You're better off using some toolkit - if you're looking for light-weight, why not try FLTK?

Upvotes: 11

Drew Hall
Drew Hall

Reputation: 29065

The "native" interface for Linux & most other Unix-like OSs is Xlib, the lowest-level C API for X11.

GTK, Qt & others are all (so far as I know) implemented in terms of Xlib at their core. As others have said, Xlib gives you maximal control but you'll have to work for it (and others may run circles around you in terms of delivering a product).

As a point of reference, I personally implemented a fairly feature-rich & modern (i.e. flowable) cross-platform (Win32 + X11) GUI library in C++. Total count is about 29 KLOC of C++, of which about 2500 lines each was required for the X11 & Win32 shimming. The rest is for platform-neutral Widget implementations. Unless you're prepared to make a commitment like that, I strongly recommend going with one of the higher level libraries (Qt would probably be my choice, though I can't stand the preprocessor approach).

BTW, a big plus for Xlib is its raw portability--any Unix box with a screen will have it, and it can be made to work on Windows & OS X as well.

Upvotes: 4

Twotymz
Twotymz

Reputation: 412

I would suggest lesstif/motif as well. It also builds on top of X and the learning curve is, in my opinion, isn't as steep as GTK or Qt. The UI's you build with it aren't going to be as sophisticated as ones you could build with GTK or Qt though. More information can be found here.

As others have mentioned you probably don't want to X it's a pain.

Upvotes: 1

Charlie Martin
Charlie Martin

Reputation: 112404

I don't want to use anything like QT, GTK, or wxWidgets or any tool kits. I'd like to learn native programming and this sort of defeats the purpose.

No you don't. Back in an early version of X11, like R1 or R2, I coded a complete "Hello, world" program in Xlib alone.

Roughly 700 lines of C.

You don't want to go there.

Upvotes: 43

ironfroggy
ironfroggy

Reputation: 8115

There is simply no such thing as "native" in this case. Windows and OS X just have an official option, while X does not.

Upvotes: 4

Andrew Kennan
Andrew Kennan

Reputation: 14157

GTK, QT and wx are toolkits that build on X to provide a friendlier API.

If you don't use an existing toolkit you'll need to write things at a very low level - directly handling mouse and keyboard events. If you want a button or a textbox you'll have to write it yourself using the low level xlib primitives.

Before trying this you're probably better off picking the toolkit of your preferred desktop environment and starting with that.

Upvotes: 5

Technical Bard
Technical Bard

Reputation: 4485

I guess you could write C code directly against Xlib, but you'd end up recreating all the functionality that GTK+ or QT provide that X doesn't alone.

Upvotes: 16

Related Questions