Hey guys, <div><br></div><div><br></div><div>this is somewhat complicated (and very much above my paygrade) but out of interest im trying out some X11 programming in C.</div><div><br></div><div>I've managed to attach to the running X11 Display, and am able to probe it for information using the following code:</div>
<div><br></div><div><br></div><div><br></div><div><div>#include<X11/Xlib.h></div><div>#include<X11/Xutil.h></div><div>#include<stdio.h></div><div><br></div><div><br></div><div>int main(){</div><div> Display *display_name /* returns a pointer containing info about our display */;</div>
<div> int depth,screen,connection;</div><div><br></div><div><br></div><div> /*Opening display and setting defaults*/</div><div> display_name = XOpenDisplay(NULL); /*opens current display */</div><div> screen = DefaultScreen(display_name); /* returns default screen for display_name */</div>
<div> depth = DefaultDepth(display_name,screen);</div><div> connection = ConnectionNumber(display_name);</div><div> Window root_window; /* variable for storing a window handle and/or ID */</div><div><br></div><div> /*Displaying the info gathered*/</div>
<div> printf("The display is::%s\n",XDisplayName((char*)display_name));</div><div> printf("Width::%d\tHeight::%d\n",</div><div> DisplayWidth(display_name,screen),</div><div> DisplayHeight(display_name,screen));</div>
<div> printf("Connection number is %d\n",connection);</div><div><br></div><div><br></div><div> if(depth == 1)</div><div> printf("You live in prehistoric times\n");</div><div> else</div><div> printf("You've got a coloured monitor with depth of %d\n",</div>
<div> depth);</div><div> root_window = RootWindow(display_name,screen); /* determine root window of screen */</div><div><br></div><div> printf("Root window of ID: %d found.\n",root_window);</div><div>
/*Closing the display*/</div><div> XCloseDisplay(display_name);</div><div>}</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>
<div>I can also create a simple window that the window manager handles, and I can also draw simple shapes and write text to the window I've created. I'd like to be able to draw to the root window, (IE I want to draw a rectangle on top of all other windows, using the entire display as my canvas, rather than a window.) the code for this is as follows:</div>
<div><br></div><div><br></div><div><div>#include<X11/Xutil.h></div><div>#include <X11/Xos.h></div><div>#include<stdio.h></div><div><br></div><div><br></div><div>int main(){</div><div> Display *display_name /* returns a pointer containing info about our display */;</div>
<div> int depth,screen,connection;</div><div> char string[] = "TESTING!";</div><div><br></div><div> GC gc; /* contains Graphical context handle */</div><div><br></div><div> /* next two lines create variables for defining the GC setup */</div>
<div> XGCValues values;</div><div> values.cap_style = CapButt;</div><div> values.join_style = JoinBevel;</div><div> unsigned long valuemask = GCCapStyle | GCJoinStyle;</div><div><br></div><div><br></div><div>
/*Opening display and setting defaults*/</div><div> display_name = XOpenDisplay(NULL); /*opens current display */</div><div> screen = DefaultScreen(display_name); /* returns default screen for display_name */</div><div>
depth = DefaultDepth(display_name,screen);</div><div> connection = ConnectionNumber(display_name);</div><div> Window root_window; /* variable for storing a window handle and/or ID */</div><div><br></div><div> /*Displaying the info gathered*/</div>
<div> printf("The display is::%s\n",XDisplayName((char*)display_name));</div><div> printf("Width::%d\tHeight::%d\n",</div><div> DisplayWidth(display_name,screen),</div><div> DisplayHeight(display_name,screen));</div>
<div> printf("Connection number is %d\n",connection);</div><div><br></div><div><br></div><div> if(depth == 1)</div><div> printf("You live in prehistoric times\n");</div><div> else</div><div> printf("You've got a coloured monitor with depth of %d\n",</div>
<div> depth);</div><div> root_window = RootWindow(display_name,screen); /* determine root window of screen */</div><div><br></div><div> printf("Root window of ID: %d found.\n",root_window);</div><div>
/*Closing the display*/</div><div><br></div><div><br></div><div><br></div><div><br></div><div> gc = XCreateGC(display_name,root_window,valuemask, &values); /* create a Graphical Context, I think this a\</div><div>cts like a canvas? :3 */</div>
<div> if (gc < 0) {</div><div> fprintf(stderr,"XCreateGC: \n");</div><div> }</div><div><br></div><div>/* use the canvas to write text */</div><div><br></div><div>XDrawString(display_name,root_window,gc,800,600, string, strlen(string));</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> XCloseDisplay(display_name);</div><div>}</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div>and it compiles cleanly, however upon executing, i never see string[] drawn on the screen.</div>
<div><br></div><div><br></div><div><br></div><div>anyone have previous experience, or programming insight that can help me?</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br clear="all">
<br>-- <br><br>Nick Walker<br>President : The Linux Society<br>UAD Ethical Hacker<br>
</div>