Add WINGs tutorial
[whome.git] / WINGs_tutorial / WINGstep1.html
blob61c35bb2196b8e62d856536c7072702a447140c4
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <!-- saved from url=(0074)WINGStep1.html -->
3 <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3 Steps to Make a WINGs User Interface</title>
4 <meta http-equiv="Content-Type" content="text/html">
5 <meta name="keywords" content="WINGs, tutorial, Introduction, C, programming, GUI, Window Maker, Linux">
6 <meta name="description" content="WINGs library tutorial">
7 <meta name="license" content="GNU Free Documentation License">
8 <!-- <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> -->
9 </head>
11 <body>
12 <table align="JUSTIFY" width="100%"><tbody><tr><td align="LEFT"><a href="WINGsIntro.html">LAST: Introduction</a></td> <td align="CENTER"><a href="WINGtoc.html">Contents</a></td><td align="RIGHT"><a href="WINGStep2.html">NEXT: Step 2 Processing Events</a></td></tr></tbody></table>
14 <h4>Step 1: Six lines show a window on the screen</h4>
15 <p>
16 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.
17 </p><h5>Application <a name="FirstWindow">FirstWindow</a></h5>
18 <pre><code>#include &lt;WINGs/WINGs.h&gt;
20 int main (int argc, char **argv){
22 Display *display;
23 WMScreen *screen;
24 WMWindow *win;
26 display = XOpenDisplay("");
27 screen = WMCreateScreen(display, DefaultScreen(display));
28 win = WMCreateWindow(screen, "");
30 WMRealizeWidget(win);
31 WMMapWidget(win);
33 WMScreenMainLoop(screen);
35 </code>
36 </pre>
37 <p>The order in which things are created is display -&gt; screen -&gt; window. A display is your pc, with keyboard and mouse. Its name is what you may see if you type into your xterm <code>echo $DISPLAY</code>. The answer might very well be:<kbd>:0.0</kbd>. Your PC may have more than one screen. So, after connecting to the display with <code>XOpenDisplay</code>, you must open a screen with <code>WMCreateScreen</code>. The display knows which screen is your default screen, and there is a function <code>Defaultscreen</code> 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.
39 You complete the window, and put it on the screen with <a name="WMMap"><code>WMMapWidget(WMWindow *window)</code></a>, and <code>WMRealizeWidget(WMWindow *window)</code>. 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 <code>WMRealizedWidget</code>ed. 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 <code>WMScreenMainLoop(WMScreen *screen)</code>. <code>WMMapWidget</code> makes a widget visible. You can also <code>WMUnmapWidget</code> them.
40 </p><p>The source code is <a href="FirstWindow.c">here</a>. 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 <em>may</em> be able close the window by clicking on the close button. More about this in a <a href="WINGStep1.html#talkCloseWindow">moment</a>.
42 </p><h6>Setting some properties</h6>
43 <p><em>After</em> creating the window with <code>WMCreatWindow</code>, and before mapping it, its <a name="WindowProps">properties</a> can be set. Function names speak for themselves.
44 </p><ul><li><code>WMResizeWidget(WMWindow *window,size-t WinSizePixels,int WinSizePixels)</code>
45 </li><li><code> WMSetWindowTitle(WMWindow *window, const char **titlestring)</code>
46 </li><li><code> WMSetWindowMinSize(WMWindow *window,int s,int s)</code>
47 </li><li><code> WMSetWindowAspectRatio(WMWindow *window,int t,int t, int t, size-t t)</code>
48 </li><li><code> WMSetWindowResizeIncrements(WMWindow *window,int Size,int Size)</code>
49 </li><li><code> WMSetWidgetBackgroundColor(WMWidget *window, WMColor *color)</code>
50 </li></ul>
51 A WMColor colour can be created and undone with
52 <ul><li><code>WMColor * WMCreateRGBColor (WMScreen *screen, unsigned short red, unsigned short green, unsigned short blue, Bool exact)</code>
53 </li><li><code>void WMReleaseColor (WMColor *color)</code>
54 </li></ul>
55 The resulting colour is a RGB combination..
56 <p>After inserting whichever functions you like, compile the code again.
58 </p><h6><a name="talkMissing">Something is missing</a></h6>
59 <p> Let us go back to the difference in <a name="talkCloseWindow">behaviour</a> under different window managers. Open an xterm, and run your application FirstWindow) from the command line <kbd>./FirstWindow</kbd>, 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 <em>command line</em> 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 <kbd>Broken pipe</kbd>. fvwm has more funky messages like <kbd>XIO: fatal IO error 104 (Connection reset by peer) on X server ":0.0" after 1320 requests (1319 known processed) with 1 events remaining.</kbd>, or <kbd>X connection to :0.0 broken (explicit kill or server shutdown)</kbd>. So one window manager disables a button, and the others give error messages. We have a problem to solve in any of them.
61 </p><table align="JUSTIFY" width="100%"><tbody><tr><td align="LEFT"><a href="WINGsIntro.html">LAST: Introduction</a></td> <td align="CENTER"><a href="WINGtoc.html">Contents</a></td><td align="RIGHT"><a href="WINGStep2.html">NEXT: Step 2 Processing Events</a></td></tr></tbody></table>
64 </body><style type="text/css">embed[type*="application/x-shockwave-flash"],embed[src*=".swf"],object[type*="application/x-shockwave-flash"],object[codetype*="application/x-shockwave-flash"],object[src*=".swf"],object[codebase*="swflash.cab"],object[classid*="D27CDB6E-AE6D-11cf-96B8-444553540000"],object[classid*="d27cdb6e-ae6d-11cf-96b8-444553540000"],object[classid*="D27CDB6E-AE6D-11cf-96B8-444553540000"]{ display: none !important;}</style></html>