You are on page 1of 4

Write For Us

Submit Tips

Subscribe to Print Edition

Contact Us

Search

HOME

REVIEWS

HOW-TOS

CODING

INTERVIEWS

FEATURES

OVERVIEW

BLOGS

SERIES

IT ADMIN

Graphics Using Xlib, Part 1


By Amol Takkalki on June 1, 2011 in Concepts, Developers, Overview 0 Comments

Search for:

Search

This article introduces you to the X Window System, with the aim of helping developers understand how to use the Xlib library effectively.
The X Window System has a very distinct place in Linux history. Originally developed at MIT in 1984, X works with multiple applications simultaneously, generating text and graphics in monochrome, colour and bitmap display. X also provides facilities for generating multi-font text and two-dimensional structures like lines, polygons and circles. X even provides a basic framework for building graphical user interfaces. X is simply another application sitting on the top of the Linux kernel. To start with, you may be confused between X Window System and Xlib. Actually, X is fundamentally composed of network protocols, which are quite complex, and consist of bits and message transfers. To reduce complexity, different libraries handle the complexity internally, providing programmers with an API. Xlib is the library for the C programming language.

Get Connected RSS Feed Twitter

The history and design of X


X was created as a research project in the early 80s. The committee responsible for X is the MIT X Consortium. The lead programmer was Robert Schiefler. In the early 90s, X was ported to run on Linux an architecture that was known as the XFree86 system. XFree86 provides a client/server interface between the display hardware and the desktop environment. With X, it was possible, for the first time, to write programs for an entire class of machines, rather than limited to a particular hardware manufacturer. Programmers could write programs that ran on almost any combination of hardware possibly without even recompiling them. Let us now look at the client-server architecture of X. The server is the program that controls the display, while user applications are clients. The server passes user inputs to the respective/active client program, and displays the information provided by the client program. The server acts as an intermediary between clients running on local or remote systems, and the resources of the local or remote system. The design of X introduced the idea of X terminals thin clients that ran only an X server and connected to a large server computer to actually run useful programs. These were executed on the server system, and were displayed to the user on the terminal. The X client-server architecture even enabled users to have X programs display their output on a Windows system, while the program itself ran on a UNIX machine which actually is one of the most significant features of X. The following figure gives a schematic diagram of how this works.

LINUX For You on

Follow

+2,531

Find us on Facebook

Open Source For You


Like 256,388 people like Open Source For You.

F acebook social plugin

Schematic diagram explaining the w orking of X

X clients (programs) are written using Xlib to communicate with the X protocol. The X protocol defines each packet of information that is transferred between the server and Xlib, which is in one of the following forms: Request (from Xlib to the server): Information like specifications for circles. Reply (from server to Xlib): In certain requests, there is a reply. Events (from server to Xlib): Information of the user action like a mouse click. Errors (to the client): Errors are handled by an error-handling routine in Xlib. X clients do not actually control display-related attributes like the window size or position. In fact, clients must not be dependent on a particular window configuration, though a client can give hints about how long, and where it would like to be displayed. The screen layout and the style of user interaction with the system, are managed by an X Window manager. Some of you might be wondering how the requests are handled. Well, Xlib groups requests, instead of sending them one by one. This grouping also helps improve network performance, as the longer and less frequent transfers reduce the overall load. Normally, after an event arrives at a client, the application generates more requests to draw for example, highlighting the border of a button when the user moves the mouse pointer over it. These responses stay queued in Xlib, until all the events that have already arrived have been processed. The schematic diagram above gives a clear picture about the whole process. When an application starts, all the requests that create the initial appearance (like a splash image) are queued up by Xlib. After the initial loading is done, the application waits for user input from the server. After the user activity is detected, the server sends the requests to Xlib. Please note that the server does not queue or group requests; it acts immediately on any request received from the user or Xlib. Here, Xlib sends the requests to the client in the order in which they were received. In case there is an error, the application throws an error message to the server, and it generates the necessary output.

Popular

Comments

Tag cloud

August 13, 2013 46 Comments Diksha P Gupta

India has immense under-utilised talent in the cloud security space


June 20, 2013 5 Comments sophie-samuel

New and amazing features of Linux


June 20, 2013 3 Comments Priyanka Sarkar

What it Takes to be an Open Source Expert


August 24, 2013 3 Comments Priyanka Sarkar

Secure Your Career with Ethical Hacking!


August 24, 2013 0 Comments Shashwat Pant

Get Fit With Android

Whats next?
This article was purely theoretical, and aimed to generate awareness about Xlib. I would personally recommend that you understand all the concepts, to better enable you to write a program in Xlib with a proper flow. This is important, because you have to open and close a connection with the server; undetanding the flow lets you know which function to use at which point in time. In the next article, I will demonstrate a simple program for plotting a series of points in a graph. The concepts explained in this part will definitely have an impact on your further understanding. See you soon!
Feature image courtesy: Sean MacEntee. Reused under the terms of CC-BY 2.0 License.

Related Posts:
Graphics Using Xlib, Part 2: Writing Programs Creating Your Own Server: The Socket API, Part 1 The Socket API, Part 3: Concurrent Servers Use XMPP to Create Your Own Google Talk Client The Socket API, Part 4: Datagrams
Tags: API, C, client server architecture, client/server, display hardware, graphical user interfaces, grapnics, GUI, LFY June 2011, MIT, network protocols, Robert Schiefler, Sean MacEntee, UI, unix, user applications, window manager, x consortium, X server, X Window System, Xlib, xlib library

Article written by:


Amol Takkalki
The author has been using Linux for the past three years, and is a big fan of it. His hobbies are photography and programming. Connect with him: Website

Previous Post

Next Post

The Comperhensive LAMP Guide, Part-1: Compiling and Optimising Apache

Web Application Penetration Testing Using Samurai

AROUND THE WEB

ALSO ON LINUX FOR YOU

What's this?

What the Bible Says About Money (Shocking) Moneynews 'X-Force' Will Be the Next X-Men Movie Stack Avoid Alzheimer's Disease: Here's What May Cause It Newsmax Health Make Egg Rolls at Home? Yes, You Can: Here's How FOODIE

India has immense under-utilised talent in the cloud 46 comments Secure Your Career with Ethical Hacking! 3 comments Cyber Attacks Explained: The Botnet Army 1 comment GNOME Extensions Spicing Up the Desktop Experience 1 comment

0 comments Leave a message...


Newest Community Share

No one has commented yet.

C o m m e n t fe e d

Su b s cri b e vi a e m a i l

Reviews

How-Tos

Coding

Interviews

Features

Overview

Blogs

Search
Popular tags
Linux , ubuntu, Java, MySQL, Google, python, Fedora, Android, PHP, C, html, w eb applications , India, Microsoft, unix , Window s , Red Hat, Oracle, Security , Apache, xml, LFY April 2012, FOSS, GNOME, http, JavaScript, LFY June 2011, open source, RAM, operating systems

For You & Me Developers Sysadmins Open Gurus CXOs Columns

All published articles are released under Creative Commons Attribution-NonCommercial 3.0 Unported License, unless otherw ise noted. LINUX For You is pow ered by WordPress, w hich gladly sits on top of a CentOS-based LEMP stack.

You might also like