LAST: Introduction ContentsNEXT: Step 2 Processing Events

Step 1: Six lines show a window on the screen

The WINGs library allows you to get a window on the screen with a few lines of C-code. The following source code will give a non-responsive empty window. By adding a short function and just one extra line of code, we shall enable it to be closed by clicking the destroy button on the title bar.

Application FirstWindow
#include <WINGs/WINGs.h>

int main (int argc, char **argv)
{
   Display *display;
   WMScreen *screen;
   WMWindow *win;

   WMInitializeApplication("put-your-app-name-here", &argc, argv);
   display = XOpenDisplay("");
   screen = WMCreateScreen(display, DefaultScreen(display));
   win = WMCreateWindow(screen, "");
 
   WMRealizeWidget(win);
   WMMapWidget(win);

   WMScreenMainLoop(screen);
}

The order in which things are created is display -> screen -> window. A display is your pc, with keyboard and mouse. Its name is what you may see if you type into your xterm echo $DISPLAY. The answer might very well be::0.0. Your PC may have more than one screen. So, after connecting to the display with XOpenDisplay, you must open a screen with WMCreateScreen. The display knows which screen is your default screen, and there is a function Defaultscreen to tell you that. Your application will need to open a window in that screen, and that window is what you would like to interact with. You complete the window, and put it on the screen with WMMapWidget(WMWindow *window), and WMRealizeWidget(WMWindow *window). Omitting either of these two functions, will have as result that your programme is stuck and you won't see anything on the screen. IN general, a widget is complete when WMRealizedWidgeted. As long as you do not map it, you will not see it. The other way round, it won't work. You cannot map a widget which has not been realized. After WMrealizing the window, you set the interface in motion by calling WMScreenMainLoop(WMScreen *screen). WMMapWidget makes a widget visible. You can also WMUnmapWidget them.

The source code is here. There is an extra intialization line which organizes the data the WINGs functions work with. Compile it: The application will show a grey area inside of the borders which your window manager provides. If you started the programme by running ./FirstWindow from an xterm, you can stop it by using ctrl-c from the command line. If you started it in the graphical interface by double clicking it, you may or may not be able to close it with the close button on the title bar. You'll notice that in Windowmaker the button is disabled, and you need to kill the application (double click). If you are using a different window manager you may be able close the window by clicking on the close button. More about this in a moment.

Setting some properties

After creating the window with WMCreatWindow, and before mapping it, its properties can be set. Function names speak for themselves.

A WMColor colour can be created and undone with The resulting colour is a RGB combination..

After inserting whichever functions you like, compile the code again.

Something is missing

Let us go back to the difference in behaviour under different window managers. Open an xterm, and run your application FirstWindow) from the command line ./FirstWindow, that is, if it's in your current directory. We have seen that under windowmaker, the close button is disabled, and you can only close the window by using ctrl-c. Now switch to a different window manager, like xfce4 or (yes) fvwm2. Run FileName from the command line in an xterm. Click on the close button in the title bar. The window closes, but that is not all. You are getting an error message in your xterm, when you close the window. xfce4 says Broken pipe. fvwm has more funky messages like XIO: fatal IO error 104 (Connection reset by peer) on X server ":0.0" after 1320 requests (1319 known processed) with 1 events remaining., or X connection to :0.0 broken (explicit kill or server shutdown). So one window manager disables a button, and the others give error messages. We have a problem to solve in any of them.

LAST: Introduction ContentsNEXT: Step 2 Processing Events