How Does The *Nix Gui Work

How does the *NIX GUI work?

Essentially, the GUI bits are individual libraries that include the chrome (stuff around your program's window), and usually include a bunch of other stuff like desktop toolbars and so on. GNOME and KDE are desktop environment examples of this.

They each include a window manager, which is the bit that tells your programs precisely where to draw, and how to draw the chrome.

Below them, you've got the X framework, which provides the API that the window managers use to paint on your screen. So X depends on your graphics drivers, which tell it how to interact with your hardware.

Above your window managers, you've got your actual programs. Each of those makes calls to the window manager to do generic things like "give me a 50x50 window with a close button".

The actual widgets drawn by a program generally utilize a graphics toolkit like the one included with GNOME. KDE includes the Qt toolkit.

There's a good selection of wm's here http://xwinman.org/

How are GUI's for OS created

This is a very broad question and as far as I know that's not the ideal format for a StackOverflow question. If you have searched Google then elaborate why the Google search results weren't sufficient, and ideally elaborate which specific things about the search results you are confused with, if anything. Also it would have been a good idea to search StackOverflow itself for similar questions before creating a new question. See the "Asking" page here: https://stackoverflow.com/help/how-to-ask

That said the GUI you're asking about isn't necessarily part of the operating system. Strictly speaking the operating system refers to the kernel, which is the software that manages hardware devices and scheduling of processes, and a user interface which may or may not involve graphics (rather than just a command line interface). Though in common parlance the "operating system" can refer to both the kernel and a GUI consisting of a windowing system and a desktop environment.

Variations of this question appear to have already been asked around StackOverflow and StackExchange. See these pages:

What is Linux’s native GUI API?

How does the *NIX GUI work?

https://unix.stackexchange.com/questions/250375/how-does-gui-in-unix-linux-actually-work

https://superuser.com/questions/1173074/how-do-the-componets-of-a-gui-work-in-linux

What's a decent events library for non-GUI applications under *nix? (C++)

Have you looked at the
Boost.Signals library? (I haven't used it myself.)

Get Spacemacs/Emacs GUI version to recognize nix-shell environment

I was able to fix this issue by running space emacs in daemon mode.
https://www.emacswiki.org/emacs/EmacsAsDaemon

in the directory with default.nix:

nix-shell .
emacs --daemon
emacsclient -c -a emacs

shifting from windows to *nix programming platform

Linux is the most accessible and has the most mature desktop functionality. BSD (in its various flavours) has less userspace baggage and would be easier to understand at a fundamental level. In this regard it is more like a traditional Unix than a modern Linux distribution. Some might view this as a good thing (and from certain perspectives it is) but will be more alien to someone familiar with Windows.

The main desktop distributions are Ubuntu and Fedora. These are both capable systems but differ somewhat in their userspace architecture The tooling for the desktop environment and default configuration for system security works a bit differently on Ubuntu than it does on most other Linux or Unix flavours but this is of little relevance to development. From a user perspective either of these would be a good start.

From a the perspective of a developer, all modern flavours of Unix and Linux are very similar and share essentially the same developer tool chain. If you want to learn about the system from a programmer's perspective there is relatively little to choose.

Most unix programming can be accomplished quite effectively with a programmer's editor such as vim or emacs, both of which come in text mode and windowing flavours. These editors are very powerful and have rather quirky user interfaces - the user interfaces are ususual but contribute significantly to the power of the tools. If you are not comfortable with these tools, this posting discusses several other editors that offer a user experience closer to common Windows tooling.

There are several IDEs such as Eclipse that might be of more interest to someone coming off Windows/Visual Studio.

Some postings on Stackoverflow that discuss linux/unix resources are:

  • What are good linux-unix books for an advancing user

  • What are some good resources for learning C beyond K&R

  • Resources for learning C program design

If you have the time and want to do a real tour of the nuts and bolts Linux From Scratch is a tutorial that goes through building a linux installation by hand. This is quite a good way to learn in depth.

For programming, get a feel for C/unix from K&R and some of the resources mentioned in the questions linked above. The equivalent of Petzold, Prosise and Richter in the Unix world are W Richard Stevens' Advanced Programming in the Unix Environment and Unix Network Programming vol. 1 and 2.

Learning one of the dynamic languages such as Perl or Python if you are not already familiar with these is also a useful thing to do. As a bonus you can get good Windows ports of both the above from Activestate which means that these skills are useful on both platforms.

If you're into C++ take a look at QT. This is arguably the best cross-platform GUI toolkit on the market and (again) has the benefit of a skill set and tool chain that is transferrable back into Windows. There are also several good books on the subject and (as a bonus) it also works well with Python.

Finally, Cygwin is a unix emulation layer that runs on Windows and gives substantially unix-like environment. Architecturally, Cygwin is a port of glibc and the crt (the GNU tool chain's base libraries) as an adaptor on top of Win32. This emulation layer makes it easy to port unix/linux apps onto Cygwin. The platform comes with a pretty complete set of software - essentially a full linux distribution hosted on a Windows kernel. It allows you to work in a unix-like way on Windows without having to maintain a separate operating system installations. If you don't want to run VMs, multiple boots or multiple PCs it may be a way of easing into unix.

How to get started developing on *nix

Read some good books, notably Advanced Linux Programming and Advanced Unix Programming. Read also the advanced bash scripting guide and other documentation from Linux Documentation Project

Obviously, install some Linux distribution on your laptop (not in some VM, but on real disk partitions). If you have a debian like distribution, run aptitude build-dep gcc-4.6 gedit on it to get a lot of interesting developers packages.

Learn some command line skills. Learn to use the man command; after installing manpages and manpages-dev packages, type man man (use the space bar to "scroll text", the q key to quit). Read also the intro(2) man page. When you forgot how to use a command like cp try cp --help.

Use a version control system like git, even for one person tiny projects.

Backup your files.

Read several relevant Wikipedia pages on Linux, kernels, syscalls, free software, X11, Posix, Unix

Try hard to use the command line. For instance, try to do everything on the command line for a week or more. Avoid using your desktop, and possibly your mouse. Learn to use emacs.

Read about builder programs like GNU make

Retrieve several free software from their source code (e.g. from sourceforge or freecode or github) and practice building and compiling them. Study their source code

Basic tips to start (if a command is not found, you need to install the package providing it) in command line (in a terminal).

  • run emacs ; there is a tutorial menu; practice it for half an hour.

  • edit a helloworld.c program (with a main calling some hello function)

  • compile it with gcc -g -Wall helloworld.c -o helloworld; improve your code till no warnings are given. Always pass -Wall to gcc or g++ to get almost all warnings.

  • run it with ./helloworld

  • debug it with gdb ./helloworld, then

    1. use the help command
    2. use the b main command to add a breakpoint in main and likewise for your hello function.
    3. run it under gdb using r
    4. use bt to get a backtrace
    5. use p to print some variable
    6. use c to continue the execution of the debugged program.
  • write a tiny Makefile to be able to build your helloworld program using make

  • learn how to call make (with M-x compile) and gdb (with M-x gdb) from inside Emacs

Learn more about valgrind (to detect most memory leaks). Perhaps consider using Boehm's GC in some of your applications.

What is Linux’s native GUI API?

In Linux the graphical user interface is not a part of the operating system. The graphical user interface found on most Linux desktops is provided by software called the X Window System, which defines a device independent way of dealing with screens, keyboards and pointer devices.

X Window defines a network protocol for communication, and any program that knows how to "speak" this protocol can use it. There is a C library called Xlib that makes it easier to use this protocol, so Xlib is kind of the native GUI API. Xlib is not the only way to access an X Window server; there is also XCB.

Toolkit libraries such as GTK+ (used by GNOME) and Qt (used by KDE), built on top of Xlib, are used because they are easier to program with. For example they give you a consistent look and feel across applications, make it easier to use drag-and-drop, provide components standard to a modern desktop environment, and so on.

How X draws on the screen internally depends on the implementation. X.org has a device independent part and a device dependent part. The former manages screen resources such as windows, while the latter communicates with the graphics card driver, usually a kernel module. The communication may happen over direct memory access or through system calls to the kernel. The driver translates the commands into a form that the hardware on the card understands.

As of 2013, a new window system called Wayland is starting to become usable, and many distributions have said they will at some point migrate to it, though there is still no clear schedule. This system is based on OpenGL/ES API, which means that in the future OpenGL will be the "native GUI API" in Linux. Work is being done to port GTK+ and QT to Wayland, so that current popular applications and desktop systems would need minimal changes. The applications that cannot be ported will be supported through an X11 server, much like OS X supports X11 apps through Xquartz. The GTK+ port is expected to be finished within a year, while Qt 5 already has complete Wayland support.

To further complicate matters, Ubuntu has announced they are developing a new system called Mir because of problems they perceive with Wayland. This window system is also based on the OpenGL/ES API.

Can I replicate what nix-build does with nix-shell and cabal build?

In general, you are not guaranteed that the output of nix-build and the same steps in a nix-shell will equivalent. Some causes of differences:

  • nix-build can run the build in a sandbox, whereas nix-shell will not.
  • nix-shell can be invoked without the --pure flag, so that many more environment variables will be set (this lets you use GUI applications for example)
  • Although nix-shell sets the $out environment variable, it is not writable
  • A process in nix-shell runs as your user, whereas nix-build with the daemon enabled will typically run it as nixbld<n>, even with sandboxing disabled

And there's probably more I didn't think of right now.

For cabal-install and plain ghc in particular, a consequence of running without the sandbox is that it can access your user package db. This requires some care when using these tools in a nix-shell; see this answer.



Related Topics



Leave a reply



Submit