Writing generic/native look GUI linux application - linux

Is there a way to create Linux application that will have native/generic look and feel on all DEs? For example if I wrote app in GTK it will look fine/native on Gnome, but on KDE (QT) it can look ugly. I'm wonder is there a generic framework for creating UI (best if have declarative syntax for UI) independent from DE, that will create native look and feel on all DEs?

I don't think so, because I am not sure that any native look is well defined. However, toolkits like GTK (used by Gnome & XFCE) and Qt (used by KDE) are somehow standardizing some "common" (or at least usual) look... (and indeed, both Gnome and KDE define some visual and behavior guides, which are incompatible).
Did you consider making a web application -perhaps using FastCGI, or even some HTTP server library like libonion or Wt? It would use the usual browser "look and feel" ...
Notice that thanks to X11 and conventions like EWMH, applications written in GTK can inter-operate with applications written in Qt (and vice-versa), even if they are looking slightly different... And as commented by andlabs, you might make appropriate themes for them to make them look even more similar.
Also, several Unix and Linux applications (even recent ones like git) are mostly command line applications (which does the bulk of the work), with some smaller GUI wrappers, perhaps communicating with the CLI application (e.g. thru pipes). Perhaps you could organize your application likewise: have most of the work done by some command line executable and add some small
GUI wrappers above (you could then code one wrapper in GTK for Gnome and another wrapper in Qt for KDE). You could even go even further by designing and developing a free software library implementing your features, leaving the bulk of the GUI work to other developers (and accepting improvements to your free software library)?

Related

Porting windows application to linux

I have an application which I need to port on Linux. I was thinking to use Free Pascal the problem is the application uses Windows API's to perform tasks such as serial port communication etc... Is there a msdn for linux users or a book covering how linux works internaly if there are apis.
I am very confused.
Well, it's sad to say but if your code in very Windows-dependend (not VCL depended!) then probably it'll be faster to write the application from the begining rather then porting it.
But if it's only serial port matter then give a try to multiplatform SynaSer library, find it here: http://synapse.ararat.cz.
hope this help :)
Robert Love has a book on Linux Systems Programming - that will cover this area and Love's books are generally good, so it is worth looking at.
It's not entirely clear from your question, but if your concern is that there are specific calls to hardware controlling functions in your Windows application that make it difficult to port I would suggest that is a misplaced fear. Both Windows and Linux operate on the principle that the application level programmer should be kept away from the hardware and that all that should be handled by the operating system kernel and only be accessible to applications via system calls. As the kernels of different operating systems face similar demands from users/applications, they tend to have system calls that do the same sorts of things. It is necessary to match the system calls to one another but I can see no reason why that should be impossible.
What may be more troublesome is that your Windows application may rely heavily on the Windows executive's windowing code/API. Again finding analogues for your code is not impossible but is likely to be a bit more complex e.g. in Linux this stuff is generally not handled in the kernel at all (unlike Windows).
But then again, your code may be written against a portable toolkit/library like Qt which would make things a lot easier.
Good luck in any case.
If the program contains GUI code you must use linux libraries like GTK/XLIB in order to create windows, forms, buttons, etc...
Windows specific functions (like EnterCriticalSection, WaitForSingleObject or _beginthreadex) must be replaced with equivalent linux api functions (a nice tutorial can be found here:
"www.ibm.com/developerworks/systems/library/es-MigratingWin32toLinux.html") or you can use libraries such as w2lpl or wine
A useful library for this kind of problems i've found at http://www.adontec.com/windows-to-linux-port-library.htm
I've had great experiences just using WINE. (https://www.winehq.org/)
You don't really port your app at all. You just make sure it doesnt violate some of the basc constraints of WINE and just run it as is. WINE (though is says it is not) is an emulator of the windows API's and will just do the translation for you. It's pretty complete in its coverage of the API's.

Develop Windows Manager in Linux with which Library?

I want to develop a simple windows manager, but do not know which library to use. Requirements:
Take advantage of the existing high-level libraries to deal with fonts, images. Like GTK+, Clutter, GDK. But keep the design-relevance things out, which libraries should I use? Because I tried to use XCB, which is really painful. And I've heard about Wayland, and if I write it in XCB, it wouldn't be portable to Wayland.
I've read some posts on WM development, typically use XCB and Xlib, I think they are too low-level and I don't want to repeat others work. I want a more user-friendly WM, but keep simple and flexible.
The biggest issue is not the library to use. It is the complexity of the requirements, as dictated by ICCCM and EWMH.
A standard compliant window manager is quite complex, because the standards defining it are complex, and because the X11 protocol is complex.
You might fork an existing WM instead.
But any library capable of X11 protocol exchange can fit the bill.
and I am not sure that Wayland has window managers
I'd split the project in a (low-level) window manager on top of the core X11 libraries, and a high-level part implementing the UI to control the window manager, utilizing whatever toolkit you feel comfortable with.
The difficulty in using a toolkit is that these are not designed to be used from inside a window manager, i.e. the toolkit might expect to be able to send a message to the window manager and receive a reply without returning to "user" code in the middle.
Plus, this allows some more flexibility when using the window manager from different environments -- desktop integrators may choose to rewrite some of the control UI to better match the rest of the system, leaving the core service unaffected.
You can't use a high-level GUI toolkit to develop a window manager. These GUI toolkits are independent of the window manager and don't have any way to communicate directly with it - only in the ways defined by the standards.

High-level language for developing applications on Linux

On Windows I've been using C#/.NET to develop both quick and simple CLI utilities as well as big WinForms/WPF applications. Visual studio played a big part in this choice but also the language and libraries allowed me to program wide range of applications without much hassle.
I'm now looking for a similar language, or more languages, on Linux. The best choice for GUI, multi-platform applications seems to be QT, usually with C++. For console utilities the best choice seems to be some scripting language like Python. However, C++ isn't a high-level language like C# and many tasks are unnecessarily more complicated (since usually I don't look for high performance in GUI applications) and scripting languages are slower and have a higher startup time.
So, what are your languages/libraries of choice when developing applications for Linux, both ten-minute utilities and large complex GUI systems.
After a 13 year rollercoaster ride through C, C++ and Ruby, I moved to Smalltalk (Squeak and Pharo) for all my development - web, scripting (just starting here), and desktop GUI apps.
Trust me, no one was more surprised than me, but Ruby got me hooked on dynamic languages, and combined with Smalltalk's live environment, I am high on OO Koolaid. If you've never experienced it, check out this screencast: http://www.pharocasts.com/2010/02/programming-with-live-objects.html
Warning - although the language is beautifully simple, it will take a while to wean off of many unnecessary and complicated, but cherished, distractions e.g. files, databases, compile cycles, etc. Luckily the community is very friendly and extremely helpful.
Also, Squeak/Pharo run on top of a VM which works in (at least) linux, windows, and Mac, so you can develop (and share) anywhere.
Have a look at Monodevelop, It is C# and offers similar functionality as the one you are used to. And above all: it comes from the same company behind C#.
As you mention: Qt is also a possibility and one I've been using extensively. Of course, you will need to develop in C++ then. The tool you want to look at is qt-assistent.
You might be interested in wxwidgets,
http://wxwidgets.org/
regards,
/t
I use python and gtk to develop GUI applications.
With glade as UI editor you can quickly setup your application.
Doing the same thing with python/Qt(or whatever Graphical library you want) should be easily doable as well.
See here : http://docs.python.org/faq/gui.html
Python can make linux system calls; use
import os
os.system("yourFavouriteSystemCall")
Additionally, PyQt4 gives you simple access to the GUI framework Qt4. This could be a good bet for your needs.
Another option is to use QT or Wx with Python or some other scripting language
You can either use QT with Python, or Mono since you already have experience on .NET.

Is there a Core Linux API analogous to Windows WINAPI, in particular for creating GUI applications?

I'm moving from windows programming (By windows programming I mean using Windows API) to Linux Programming.
For programming Windows, the option we have is Win32API (MFC is just a C++ wrapper for the same).
I want to know if there is something like Linux API (equivalent to WINAPI) that is exposed directly to the programmer? Where can I find the reference?
With my little knowledge of POSIX library I see that it wraps around part of Linux API. But what about creating GUI applications? POSIX doesn't offer that. I know there are tons of 3rd party Widget toolkits like gtk, Qt etc. But I don't want to use the libraries that encapsulates Linux API. I want to learn using the "Core Linux API".
If there are somethings that I should know, please inform. Any programmer who is familiar with both Windows & Linux programming, please map the terminologies of Linux world so that I can quickly move on.
Any resources (books,tutorials,references) are highly appreciated.
I think you're looking for something that doesn't exactly exist. Unlike the Win32 API, there is no "Linux API" for doing GUI applications. The closest you can get is the X protocol itself, which is a pretty low level way of doing GUI (it's much more detailed and archaic than Win32 GDI, for example). This is why there exist wrappers such as GTK and Qt that hide the details of the X protocol.
The X protocol is available to C programs using XLib.
What you must understand is that Linux is very bare as to what is contained within it. The "Core" Linux API is POSIX and glibc. Linux is NOT graphical by default, so there is no core graphics library. Really, Windows could be stripped down to not have graphics also and thus not have parts of the win32 API like GDI. This you must understand. Linux is very lightweight compared to Windows.
For Linux there are two main graphical toolkits, GTK and Qt. I myself prefer GTK, but I'd research both. Also note that GTK and Qt exist for Windows to, because they are just wrappers. If you go take a look at the X protocol code for say xterm, you'll see why no one tries to actually creating graphical applications on top of it.
Oh, also SDL is pretty nice, it is pretty bare, but it is nice if your just needing a framebuffer for a window. It is portable between Linux and Windows and very easy to learn. But it will only stretch so far..
Linux and win aren't quite as different as it looks.
On both systems there exists a kernel that is not graphical.
It's just that Microsoft doesn't document this kernel and publishes an API that references various different components.
On Unix, it's more transparent. There really is a (non-GUI) kernel API and it is published. Then, there are services that run on top of this, optionally, and their interfaces are published without an attempt to merge them into an imaginary layer that doesn't really exist.
So, the lowest GUI level is a the X Window System and it has a lowest level library called Xlib. There are various libraries that run on top of this one, as you have noted.
I would highly recommended looking at the QT/C++ UI framework, it's arguably the most comprehensive UI toolkit for any platform.
We're using it at work developing cross platform apps that run on windows, osx and linux.
It also runs on Nokia's smart phone Operating System Maemo which has recently been merged with Intel's Moblin Linux OS, now called MeeGo.
This is going to sound insane since you're asking about "serious" stuff like C++ and C (and the "core linux API"), but you might want to consider building in something else. For instance:
Java Swing (many people love it! Others hate it and call it obsolete)
Mono GTK# (C# or VisualBasic or whatever you want, lots of people say it's pretty cool, but they're not not that many people)
Adobe AIR (ActionScript, you might hate it)
Titanium (totally new and unproven, but getting a lot of buzz in the iPhone world, at least)
And many other possibilities, some of which let you work on multiple platforms at once.
Sorry if this answer is not at all what you're looking for. The "real" answers on Linux are "pick a toolkit," which is also no answer at all :)
Have a look at Cairo. This something roughly similar to GDI+ and is under the hood of some of of the few usable GUI programs for Linux i.e. Firefox or Eclipse (SWT). It wraps most the natsy and ancient Linux stuff for you into a nice API that runs on most Linux installations without locking you into a entire subsystems like GTK or QT.
There is also the docs for the two different desktop platforms: Gnome and KDE that might help you down that road.

What should I choose: GTK+ or Qt? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Can someone suggest what's the best uses for those libraries today? Is it just GUI, or do they have database, XML, networking, threading, etc support too?
I was reading about them, and considered starting to learning/using one of them.
What is the most common one? What's the difference between them? Why would you choose one over the other?
As you seem to primarily target Linux, then the choice mostly depends on the programming language you want to use.
If you code in C, then obviously go for GTK+
If you code in C++, go for Qt, otherwise you will need Gtkmm (a C++ wrapper over GTK+)
If you code in Python, both GTK+ and Qt have bindings for the language: see PyGtk, PyQt and PySide (the one launched by Nokia themselves).
If you code in Java, Qt is no more a viable option imho as Nokia discontinued Qt Jambi (the Java bindings for Qt).
Also, Qt is more top-notch regarding its scenegraph QGraphicsScene API, its scripting engine built over Javascript Core (the engine powering WebKit), its state machine and animations framework, and the declarative UI.
GTK+ doesn't offer that much although you can use Clutter alongside with it.
If you're specifically looking into DB, XML (GTK+ has a parser for a subset of XML) and threading (GTK+ has GLib) features then Qt will offer all that in QtSql, QtXml and QtConcurrent.
All in all, I would say Qt is a sure choice. But GTK+ is very capable as well.
I'm not sure you will get a crystal clear answer for your question, which explains why some people keep preferring Gnome over KDE or vice-versa. Choose what works best for you.
PS: I you plan to also target Symbian, then go for Qt.
EDIT: Something that is also great with Qt is QtWebView: it brings Chromium into your Qt application to display web content. Others are embedding web content into their application using for instance Awesomium or Berkelium.
I've used GTK+, QT and wxWidgets before. Here's a brief summary:
For my first cross platform UI project I decided to go for wxWidgets mainly because at the time the license wasn't as restrictive as QT's (QT was GPL and only for Linux) and it had platform specific UI (unlike GTK). The project worked out well but there were quite a few glitches getting it to compile and run properly in other platforms - sometimes some events were fired up differently and such. Also GDI in wxWidgets was pretty slow.
Next I used GTK for a different project in python. For this I used the python bindings and everything worked out more or less smoothly. I didn't quite like the fact that the UI didn't look native on Windows and Mac and also when you launch a GTK+ app it always debug outputs loads of CRITICAL warnings which seem fine to ignore. :S
Finally, I did a very simple QT project now that Nokia has acquired it and was brilliant. The best of the three. First off, if you're not an old schooler who prefers VI or Emacs, QtCreator is brilliant. I really love VI and used it for years but I much prefer QtCreator for C++ QT projects. Regarding the library I also liked a lot the documentation and the APIs provided. QT has a concept of slots and signals which introduce new C++ keywords and a preprocessor. Basically, after reading a tutorial you'll get it easily and will start to love it. I'm now doing iPhone dev and it does feel a bit like Cocoa's/Interface Builder's UI paradigm.
Summary: I'd go for QT hands down. The license is pretty good and the SDK and documentation really nice.
I have never used GTK, but from my personal experience using Qt:
It is much more than a simple GUI. It's a whole application framework. I used to think of it as the Java libraries for C++. It provides all you mention -- database, XML, networking and threading, and more. It also provides things such as containers and iterators, and counterparts to a number of boost libraries.
The thing that impressed me most when starting to use Qt was the extremely extensive documentation. You get a program called Qt Assistant, which provides fully indexed and searchable API documentation on your desktop, as well as numerous code examples and tutorials. I found it made a big difference in searching the web each time for API info. Very quick access when you need to remember a method signature.
I am not sure which is most common; that's probably hard to measure accurately. They're certainly both popular. As Gnome is the default desktop of Ubuntu, and Gnome sits on top of GTK, it obviously has widespread usage. Of course, KDE is very popular as well. Nokia is heavily pushing Qt in the mobile space -- their Maemo OS, used on the new N900 for example, is soon to switch to Qt as the default toolkit (currently it is GTK.) I believe Qt will also soon become the default toolkit for Symbian OS.
I have not used Qt Creator, but I have heard many good things about it. It is a C++ IDE with obvious heavy integration with Qt. It also has fake vim emulation which is always nice if you like that kind of thing!
Qt uses qmake for build configuration. I found this much nicer than having to write your own makefiles. I do not know what GTK uses for building.
A couple of things I found a bit offputting with Qt at first was its big uses of preprocessor macros. The signal/slots system provides a nice mechanism for event/message passing in your application, but it does feel a bit like magic that may not be easily portable to another toolkit if you ever want to. Also, the moc (meta-object compiler), while I'm not entirely sure what it does, also feels a bit too much like magic going on behind the scenes.
All in all, though, I would recommend Qt, particularly if you are learning. It has really amazing documentation and a nice IDE, and busy forums. You'll be able to build C++ apps very rapidly with it, particularly with the QML coming in 4.7.
It probably depends on what you want to do. I would recommend Qt, because it's more than GUI, it has nice Python bindings (so does Gtk), and GUI libraries themselves are (subjectively speaking) more pleasant then Gtk.
Gtk is on the other hand more common in linux world, so you can probably get more help on the web. Reason for widespread of Gtk probably has more to do with Gnome and Ubuntu, rather then technical merits, but if you want you software to blend nicely with those two, you'll achieve that more easily with Gtk.
Qt for one sure has solid DB, network, threading support etc... It does a lot more then just cross-platform GUI (and it does most of it quite well).
I'd recommend it over GTK+.
Qt. It's not only object oriented, is "good" object oriented.
It's based on a "subset" of C++ that doesn't rely on the obscurity of C++ (but you are allowed to stick with them, if you fancy masochism ;) ).
It has a strong momentum now that Nokia bought it (actually Nokia did ~2/3 years ago). It's going to be in all Nokia AND Intel mobile devices (smartphones, netbooks, tablets).
It's the backbone of KDE, so it's very mature, but it's designed in a very flexible way, that makes it possible to support TODAY all the latest "cool stuff" that a more-then-just-GUI framework should have.
Go for it.
Just adding QT advantages to other answers.. QT has great documentation, its own IDE & GUI creator and enhances C++ with some new concepts like slots/signals (basically events).
I am not a GTK developer, so I can't compare those to the GTK world :(
It also looks like Nokia is about to use Qt everywhere, like on Maemo
If you want your app to run on iOS, Android, Blackberry, other mobile platforms, Windows, Mac OSX, and Linux, use Qt.
qt-project.org

Resources