Ok heres the full program I'm using:
Code:
#include<stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
int main (int ArgC, char **ArgV)
{
Display *cdisDisplay;
int ciScreenNum;
Screen *cscrScreenPtr;
XWMHints *xwmhHints;
XClassHint *xchClass;
XTextProperty xtpWinName, xtpIconName;
XSizeHints *xshSize;
char *pcIconName = "Icon Name?", *pcWinName = "Window Name?", *pcProgName = "Test App";
XEvent xeEvent;
Window Handle;
cdisDisplay = XOpenDisplay(NULL);
if (cdisDisplay == NULL)
{//Failed to connect to an X Server
printf("\nFailed to connect to the display\n");
return 0;
}
else
{
ciScreenNum = DefaultScreen(cdisDisplay);
cscrScreenPtr = DefaultScreenOfDisplay(cdisDisplay);
}
Handle = XCreateSimpleWindow(cdisDisplay, RootWindow(cdisDisplay, ciScreenNum), 0, 0, 200, 200, 0, BlackPixel(cdisDisplay, ciScreenNum), WhitePixel(cdisDisplay, ciScreenNum));
//Allocate space for the hints
xshSize = XAllocSizeHints();
xwmhHints = XAllocWMHints();
xchClass = XAllocClassHint();
xshSize->flags = PPosition | PSize;
XStringListToTextProperty(&pcWinName, 1, &xtpWinName);
XStringListToTextProperty(&pcIconName, 1, &xtpIconName);
xwmhHints->initial_state = NormalState;
xwmhHints->input = True;
xwmhHints->flags = StateHint | InputHint;
xchClass->res_name = pcProgName;
xchClass->res_class = "Base Win";
XSetWMProperties(cdisDisplay, Handle, &xtpWinName, &xtpIconName, 0, NULL, xshSize, xwmhHints, xchClass);
XSelectInput(cdisDisplay, Handle, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask);
XMapWindow(cdisDisplay, Handle); //Show the window
while (1)
{
XNextEvent(cdisDisplay, &xeEvent);
switch (xeEvent.type)
{
case (ConfigureNotify) :
{
printf("Window moved or resized!\n");
break;
}
case (ButtonPress) :
{
printf("Mouse button %d pressed!\n", xeEvent.xbutton.button);
break;
}
case (DestroyNotify) :
{
printf("Window killed!\n");
}
default :
{
printf("Unknown event: %d (discarding)\n", xeEvent.type);
break;
}
}
}
}
The output looks something like this, after moving the window a bit and clicking in it, then closing hte window using that top right 'X' button:
Code:
Unknown event: 21 (discarding)
Window moved or resized!
Unknown event: 19 (discarding)
Unknown event: 12 (discarding)
Window moved or resized!
Window moved or resized!
Window moved or resized!
Mouse button 1 pressed!
Mouse button 3 pressed!
Mouse button 2 pressed!
X connection to :0.0 broken (explicit kill or server shutdown).
I am missing the XSetWMProtocols() call suggested by Ken Fitlike, I'll give that a shot and see how it does. From what I read that sounds like it could be hat I need.