LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What all is there for programming for X in C? (https://www.linuxquestions.org/questions/programming-9/what-all-is-there-for-programming-for-x-in-c-718197/)

Mol_Bolom 04-10-2009 08:26 AM

What all is there for programming for X in C?
 
I came across the gtk tutorials and have been going through them and find it to be fairly simple. So I was just wondering what else is there for programming in C. Most of what I have found so far is c++ related.
(Note: I really don't care for learning how to write games/image manipulation programs. I am only wanting to learn how to write text based programs using unicode and ascii.)


Oh, and if someone might know the answer to this. What are the correct terms to search for tutorials on how to scroll the screen in the console? I had tried to learn this before using DOS many years ago, but I don't know if the interupt calls are still used the same way as they were back on an old 486.

SciYro 04-10-2009 02:13 PM

What do you mean by 'text based program'?

Can your program function (assuming it did not need unicode) in the normal console?

If that is the case, then simply using a unicode aware terminal emulater in X should be all thats needed (I believe most emulaters need a argument passed that says to use unicode).

If thats not the case, then you will need a GUI toolkit. Only GTK is written in C, others are in C++. I believe Tk has C bindings tho, but I'm not aware of anyother toolkit thats even remotely popular that has plain C support.

And if your using interupts, stop. Look at Ncurses, if there is nothing about screen scrolling in there, then it probably cant be done and youll just have to implement it yourself. (note, I'm assuming your refering to scrolling the text console, if not, then use a scrolled window widget).

edit: Ah, there is also Cairo (not exactly a toolkit, and it'll require some extra low-level work with X to make it work fully) with Pango for text rendering.

Mol_Bolom 04-10-2009 03:20 PM

Thanks. I downloaded the ncurses manual and will have a look at it when I can.

As for text based programming, no I don't have a program yet. I'd like to, I am getting rather bored with all the tutorials and command line programs. Heck, I'd at least like to know how to position the cursor on screen. I did find it once, but haven't found it again and have been searching for weeks.

Anyway, why I was looking into scrolling the screen. I haven't programmed using interrupts since about 99, and that was basically using the mouse via int86(&h33, AX, BX...) using ASIC or int86old(&h33, rect) using Qbasic, as well as the keyboard (which I think was at &h10 or &h11, too long ago to remember), and had only began learning how to scroll on an old 486 before switching to WinXP which Qbasic no longer worked on it.

I've only been using C and linux for a few months and don't quite know exactly how one accesses the screen, mouse, etc through the console using C and linux on a computer 1.2g to 2.0g, or if there is some other way that it is done. I've read that instead of accessing the devices by int86() one would rather use open("/dev/device", something). However, I'm beginning to think that Linux has other methods to access the devices...

Eh, my mind is still in 99, lol, and I really haven't a clue what I should read in order to access the devices. Anyway, I'll have a look at ncurses and see what it says...

Thanks again...

jiml8 04-10-2009 03:32 PM

Linux won't let you use interrupts unless you write your own kernel driver. You can move the cursor around the console using the standard escape sequences.

Any of the toolsets that are written for C++ can be invoked from C. Heck, I have been writing C++ classes that call gtk+ (and cairo and pango). Going back and forth between the two languages is not hard. In the worst case, you need stub routines that are callable by one language but call using the syntax of the other language. This is a frequent situation when using C to call C++.

You need to study /dev, /proc, and /sys. A lot of the information you want is found in those (particularly /dev).

jlinkels 04-10-2009 10:14 PM

A user interface in a text based console is not X. I think you are sufficiently aware of that if I look at your posts.

Ncurses is the way to go when programming a menu driven application, I can't really call it a GUI. I know exactly what you mean with the DOS applications using interrupts etc. I did it myself, you know what a mess it was, single user, single application, TSRs etc.

Funny because in that time Unix was already around with curses available, the predecessor of ncurses. You can do what you need, text based screen navigation, but in a really structured way without ever having to worry about hardware. Even if you SSH into another computer you still can use your ncurses based application. The most well-known curses applications might be the kernel config program (make menuconfig) and Midnight Commander (mc)

Anyhow, you might run into difficulties in this like catching keystrokes and testing the value, there is buffered and unbuffered input, you have to initialize the screen properly. But again, this all is highly structured, and once you master that, writing your application is pretty straightforward. You will find plenty examples on the internet. There is also a widget library avaible which greatly extends the ncurses toolkit. I forgot the name, but you google it easily. Use the keys 'ncurses widget toolkit'

jlinkels

Mol_Bolom 04-10-2009 11:51 PM

Thanks Jlinkels, that's exactly what I'm looking for...:D...

And as for programming in X, well, I guess I'll stick with gtk since it's used in programs more often, at least from what I've seen so far...

bigearsbilly 04-11-2009 05:12 PM

also, the VT100 escape codes are fun:
e.g.

Code:

printf "\33[2J\33[12;20H"
should put the cursor in the middle of your xterm somewhere.

p.s. that's the shell printf not the C one
but you get the idea.


(\33 is the ascii ESCAPE character)

Mol_Bolom 04-11-2009 06:22 PM

Quote:

Originally Posted by bigearsbilly (Post 3505832)
also, the VT100 escape codes are fun:
e.g.

Yeah, I came across those yesterday, was quite interesting to learn that ^[ wasn't the same as ^[ :eek:.

bigearsbilly 04-11-2009 07:36 PM

yes that's how it's usually rendered.
if you type
CTRL-V ESC
in a terminal it'll look like that.


All times are GMT -5. The time now is 01:03 AM.