What x11 header file and function would I use to change the position of the cursor on the display? I have heard there is a straight forward function on Vc++ but I wish to be able to use this on linux.
You can't trivially port programs from windows to xwindows, at least not without using a cross platform toolkit like gtk+ or Qt.
That said, the most basic way to move the pointer about on X is using the XWarpPointer() method, which is to be had by including X11/Xlib.h
EDIT:
Apparently you are using Qt after all. you need to use QCursor::setpos which is defined in QCursor
Related
ANSI.SYS is missing in windows 8.1; so how do I create cursor control in a console display?
I am currently using C; if it cannot be done in C, can it be done in C++? Config.sys is supposed to have DEVICE=ANSI.SYS.
You want to mix the ancient ancient ancient MS-DOS technologies with the modern Windows NT console. ANSI.SYS is missing because it's looong dead.
What you want to do instead is take advantage of the NT console. Here's a starting point in the API documentation. In particular, there's a guide on handling mouse input that you can use as a starting point.
You may find it easier to use a library like Termbox or pdcurses, depending on the type of program you want to write. There are even some text-based user interface (TUI) libraries, such as Turbo Vision, if you want to write that kind of program instead.
I'd like to write an application (in C) that uses the terminal of a *nix OS as its GUI. I mean an application of the kinds of emacs, vi etc. that take up the whole terminal window and jump back to the input prompt after quitting.
How would you go about doing that, preferably in C? Can someone point me to a tutorial covering that?
You need to use ncurses:
http://en.wikipedia.org/wiki/Ncurses
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
It is available on all major distros.
Well, actually this is not GUI (graphic user interface) but a text based interface. You can use the library ncurses to create such applications in C.
Use a library like ncurses, it is specifically designed for this purpose.
Throwing in alternate solutions so that this question thread does not look so monotonic:
the slang library (mc uses it, for example)
I am trying to build a program to rename a bunch of files to a specific format. Problem is, I can't figure out the best way to find, list or manipulate windows files using C (using Visual C++ 2010).
I was able to do it in C++ using FindFirstFile() but I am trying to restrict myself to C only so I'm looking for another solution, which will also be more compatible.
Thanks.
First, FindFirstFile() is not a C++ function; it is a Windows function, which on Windows is also available in C (but is not available at all on other OSes)
If you want a portable solution, you can use the glib library's directory functions to list directories in a portable manner. There are functions for globbing (ie, processing wildcards) in glib as well.
On Windows, no matter which framework you use, all the frameworks need, ultimately, to call the user mode user32::CreateWindowEx API to actually create a window on the desktop.
On Ubuntu, or indeed Linux systems in general, it seems that the choices are to use a widget framework like Wx or Qt or GTK+ to create a GUI application, but all these frameworks feel like they are wrapping something more fundamental. Do these all talk directly to X on Linux? I thought Ubuntu was moving to a non X window manager, so what are they going to use then?
What library would I use to access the window manager all these frameworks use?
They are all wrapping Xlib , if you ever switch to non-X server you will need an Xlib replacement along with it (or an Xlib wrapper).
You could in principle write your own X library by learning the X11 protocol and all the related extensions (ICCCM, desktop conventions, ...) but that is a huge task. You would use the lowest level system calls (send, recv, ...) if you did that.
Some implementations of some languages (SML, Common Lisp, Ocaml) made that choice of implementing the X11 protocol without using the Xlib or XCB C libraries. But it is such a big task that I won't recommend it.
And the Wayland that Ubuntu speaks about is not mature yet, but the toolkit libraries (like GTK and Qt) are slowly moving to support it (in addition of supporting X11).
Today, you also have the option to develop Web based applications instead of X11 based ones. Sometimes HTTP + XHTML + AJAX is simpler that recoding an X11 thing from scratch.
But don't start alone the writing of a graphical stack... it is too big a task...
X operates over a carefully specified network protocol, so you can speak this protocol directly to the server if you like. In practice, GUI toolkits wrap Xlib (and possibly Xt). Traditionally Xlib was as low as it went, but now Xlib has been reimplemented on top of a much cleaner low-level X protocol library "xcb".
I'm working on a project that's supposed to work on both Windows and Linux (with an unofficial Mac port as well) that emulates a true colour system console.
My problem is that recently there appeared a request for textfield support (yes, console-based) and it would be cool to add the possibility of copying text to clipboard and pasting from it. Is there a way of achieving this that will:
be done in C (not C++),
work in both Windows and in Linux (preprocessor macros are an option if there's no platform-independent code),
require no extra libraries to link to?
Thanks in advance for your help.
If you're not using a cross platform UI library (like wx or something), then it sounds like you're just going to have to write native clipboard code for each platform you want to support.
Remember, on Macintoshes, you copy with Command-C, not Ctrl+C :)
The clipboard is inherently an operating system defined concept. The C language itself has no knowledge of what a clipboard is or how to operate on it. You must either interface directly with the OS, or use a portability library that does this on your behalf. There is no way around this.
Personally I would define my your own function
getClipboardText();
That is defined in two different header files (linux_clipboard.h, windows_clipboard.h, etc) and then do pre-proccessor stuff to load the appropriate one accordingly. I don't really code in C/C++ so I'm sorry if that didn't make any sense or is bad practice but that's how I'd go about doing this.
#if WIN32
#include windows_clipboard.h
#endif
That sort of thing
Remember:
For linux you have to deal with different window managers (Gnome, KDE) all with different ways of managing the clipboard. Keep this in mind when designing your app.
You may be able to communicate to the clipboard by using xclip. You can use this python script here to do this job via communicating with 'dcop' and 'klipper' here. That is for KDE, I do not know how it would be done under GNOME... You may also be able to do this independantly of either GNOME/KDE by using DBUS, although I cannot say 100% confidently on that either...
Just be aware, that for a truly cross-platform job, you have to take into account of the different GUI's such as under Linux, X is the main window manager interface and either GNOME/KDE sits on top of it..I am not singling out other GUI's such as FluxBox, WindowMaker to name but a few, and that there will be a lot of platform dependant code, and also in conjunction, you will be dealing with Windows clipboard as well..all in all, a big integrated code...
Have you not considered looking at the raw X programming API for clipboard support? Maybe that might be better as I would imagine, GNOME/KDE etc are using the X's API to do the clipboard work...if that is confirmed, then the work would be cut out and be independant of the major GUI interfaces...(I hope that would be the case as it would make life easier for your project!)
Perhaps using compile-time switches, for each platform...WIN, KDE, GNOME, MAC or use the one that is already pre-defined..
Hope this helps,
Best regards,
Tom.