tags:

views:

1631

answers:

8

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.

+10  A: 

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.

Technical Bard
Agree; I think it's a different way of doing things in the Linux world.
Sydius
I understand that linux itself was originally just the console, and GUI's are added by third party programs. But It feels weird using all these toolkits in Linux, it feels like to get a GUI you need to use "hacks" or beat around the bush so to speak.
Mike Leffard
@Mike, do you feel the "hacks" when you play DirectX games using NVidia's drivers? They're third-party software.
paxdiablo
Piotr Lesnicki
+3  A: 

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.

Andrew Kennan
+46  A: 

I can see myself getting voted down for this, but such is life.

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.

Your use of the phrase "native programming" confuses me a little. If you want to learn native programming, it's to the API's 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. Me, 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.

paxdiablo
I've had to use motif directly (only because the wm we are using is developed in house) and it's not easy. I'd rather use one of the freely available UI abstraction layers
hhafez
Writing a UI in Xlib isn't like writing a UI in plain Win32, it's more like writing a UI in DirectDraw; it's much more low-level than Win32
Paul Betts
If you're not willing to go through half a dozen abstraction layers, Linux development is not for you. ;)
jalf
@jalf: Most development nowadays, actually.
Joey
+3  A: 

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

ironfroggy
Well, X does have an official option, it's just a a very low (ugly) level.
paxdiablo
+27  A: 

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.

Charlie Martin
A: 

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.

Twotymz
+2  A: 

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.

Drew Hall
+7  A: 

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?

shash