still hacking on WindowUtils, it compiles now.. but I seem to be having difficulties with my GetProperty routine...very odd...
12 02/23/08 21:19:42.000 Calling callback for alarm 0x808e798 id 1 param=(nil) entry->when: 1203819582 time: 1203819582 <0xb7752b90>
10 02/23/08 21:19:42.000 WindowUtils::GetProperty -- getting property _NET_CLIENT_LIST <0xb7752b90>
10 02/23/08 21:19:42.000 WindowUtils::GetProperty -- Got Property: <0xb7752b90>
10 02/23/08 21:19:42.000 WindowUtils::GetClientList -- Got Client List: <0xb7752b90>
01 02/23/08 21:19:42.001 WindowUtils::FindWindowMatching -- Fell all the way through! <0xb7752b90>
01 02/23/08 21:19:42.001 Couldn't find MAME Window <0xb7752b90>
12 02/23/08 21:19:42.001 Cancel Alarm by type: 1 <0xb7752b90>
12 02/23/08 21:19:47.000 Calling callback for alarm 0x808e798 id 1 param=(nil) entry->when: 1203819587 time: 1203819587 <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetProperty -- getting property _NET_CLIENT_LIST <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetProperty -- Got Property: <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetClientList -- Got Client List: <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetClientList -- Client List Fragment: <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetClientList -- Client List converted to int: 0 <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetClientList -- Client List Fragment: <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetClientList -- Client List converted to int: 0 <0xb7752b90>
10 02/23/08 21:19:47.000 WindowUtils::GetProperty -- getting property _NET_WM_NAME <0xb7752b90>
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 20 (X_GetProperty)
Resource id in failed request: 0x0
Serial number of failed request: 12
Current serial number in output stream: 12
the code:
WindowUtils.cpp
/*
Copyright (C) 2008 Locale|CONCEPT for the LinuxMCE project.
Author: Thomas Cherryhomes <thom.cherryhomes@localeconcept.com>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
This code was based in part on:
wmctrl
A command line tool to interact with an EWMH/NetWM compatible X Window Manager.
Author, current maintainer: Tomas Styblo <tripie@cpan.org>
Copyright (C) 2003
*/
#include "WindowUtils.h"
#include "PlutoUtils/CommonIncludes.h"
#include "DCE/Logger.h"
#include <vector>
#include <map>
#include <string>
#include <cstdlib>
#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
#include <sys/select.h>
extern int errno;
using namespace std;
using namespace DCE;
#include "PlutoUtils/StringUtils.h"
#include "PlutoUtils/FileUtils.h"
#include "PlutoUtils/PlutoDefs.h"
namespace WindowUtils
{
using std::map;
using std::vector;
using std::string;
}
// Quick little hack.
inline int stoi(std::string &s)
{
return std::atoi(s.c_str());
}
/**
* GetProperty - Get an X Property.
*/
bool WindowUtils::GetProperty(Display *disp, Window win, Atom xa_prop_type, string s_PropertyName, string& s_Property)
{
Atom xa_prop_name;
Atom xa_ret_type;
int ret_format;
unsigned long ret_nitems;
unsigned long ret_bytes_after;
unsigned long tmp_size;
unsigned char *ret_prop;
char *ret;
xa_prop_name = XInternAtom(disp, s_PropertyName.c_str(), False);
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetProperty -- getting property %s",s_PropertyName.c_str());
/* MAX_PROPERTY_VALUE_LEN / 4 explanation (XGetWindowProperty manpage):
*
* long_length = Specifies the length in 32-bit multiples of the
* data to be retrieved.
*/
if (XGetWindowProperty(disp, win, xa_prop_name, 0, MAX_PROPERTY_VALUE_LEN / 4, False,
xa_prop_type, &xa_ret_type, &ret_format,
&ret_nitems, &ret_bytes_after, &ret_prop) != Success)
{
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Cannot get %s property.",s_PropertyName.c_str());
return false;
}
if (xa_ret_type != xa_prop_type)
{
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"Invalid type of %s property.", s_PropertyName.c_str());
XFree(ret_prop);
return false;
}
XFree(ret_prop);
/* null terminate the result to make string handling easier */
tmp_size = (ret_format / 8) * ret_nitems;
ret = (char *)malloc(tmp_size+1);
memcpy(ret, ret_prop, tmp_size);
ret[tmp_size] = '\0';
/* Then, convert it to a C++ string */
s_Property = string(ret);
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetProperty -- Got Property: %s",s_Property.c_str());
return true;
}
/**
* GetClientList - Get the list of clients attached to display.
*/
bool WindowUtils::GetClientList(Display *disp,vector<Window>& v_wClientList)
{
string client_list;
unsigned int i;
if (!GetProperty(disp,DefaultRootWindow(disp),XA_WINDOW,"_NET_CLIENT_LIST",client_list))
{
if (!GetProperty(disp,DefaultRootWindow(disp), XA_CARDINAL, "_WIN_CLIENT_LIST",client_list))
{
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"WindowUtils: Cannot Get Client List Properties");
return false;
}
}
string temp;
int win;
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetClientList -- Got Client List: %s",client_list.c_str());
// Now transmorgrify it into a vector of Windows
for (i=0;i<client_list.size();i+=sizeof(Window))
{
temp = client_list.substr(i,sizeof(Window));
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetClientList -- Client List Fragment: %s",temp.c_str());
win = stoi(temp);
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetClientList -- Client List converted to int: %x",win);
v_wClientList.push_back(win);
}
return true;
}
/**
* GetWindowTitle - Get Window Title given Window ID
*/
bool WindowUtils::GetWindowTitle(Display *disp, Window win, string& s_Title)
{
string s_wm_name;
string s_Net_wm_name;
if (!GetProperty(disp, win, XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", s_Net_wm_name))
{
// no _NET_WM property for window title, get it the old way.
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"WindowUtils::GetWindowTitle -- no _NET_WM_Property, getting old way.");
if (!GetProperty(disp, win, XA_STRING, "WM_NAME", s_wm_name))
{
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetWindowTitle -- no WM_NAME property either...bailing...");
return false;
} else {
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetWindowTitle -- Setting Title to WM_NAME %s",s_wm_name.c_str());
s_Title = string(s_wm_name);
return true;
}
}
else
{
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::GetWindowTitle -- Setting Title to _NET_WM_NAME %s",s_Net_wm_name.c_str());
s_Title = string(s_Net_wm_name);
return true;
}
}
/**
* FindWindowMatching - Return first Window ID matching a title fragment.
*/
bool WindowUtils::FindWindowMatching(Display *disp, string windowName, Window& win)
{
vector<Window> v_wClientList;
string title;
unsigned int i;
if (!GetClientList(disp,v_wClientList))
{
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"WindowUtils::FindWindowMatching -- Could not get client list!");
return false;
}
for (i=0;i<v_wClientList.size();i++)
{
if (!GetWindowTitle(disp,v_wClientList[i],title))
{
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"WindowUtils::FindWindowMatching -- Could not get window title for Window ID %x",v_wClientList[i]);
continue;
}
else
{
if (title.find_first_of(windowName) == string::npos)
{
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"WindowUtils::FindWindowMatching -- Couldn't match window title %s",title.c_str());
continue;
}
else
{
win = (Window)v_wClientList[i];
LoggerWrapper::GetInstance()->Write(LV_STATUS,"WindowUtils::FindWindowMatching -- Title Matched %s to Window id %x",title.c_str(),win);
return true;
}
}
}
LoggerWrapper::GetInstance()->Write(LV_CRITICAL,"WindowUtils::FindWindowMatching -- Fell all the way through!");
return false;
}
WindowUtils.h
/*
Copyright (C) 2008 Locale|Concept
www.localeconcept.com
Phone: +1 (617) 245-1354
Author: Thom Cherryhomes <thom.cherryhomes@localeconcept.com>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
This code was based in part on:
wmctrl
A command line tool to interact with an EWMH/NetWM compatible X Window Manager.
Author, current maintainer: Tomas Styblo <tripie@cpan.org>
Copyright (C) 2003
*/
/** @file WindowUtils.h
Header file for the Window Utils namespace
*/
#ifndef WINDOWUTILS
#define WINDOWUTILS
#include <string>
#include <vector>
#include <map>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/Xmu/WinUtil.h>
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
#define _NET_WM_STATE_ADD 1 /* add/set property */
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
#define MAX_PROPERTY_VALUE_LEN 4096
/**
@namespace WindowUtils
For Window Management using EWMH semantics.
*/
namespace WindowUtils
{
using namespace std;
using std::map;
using std::vector;
using std::string;
/**
* GetProperty - Get an X Property.
*/
bool GetProperty(Display *disp, Window win, Atom xa_prop_type, string s_PropertyName, string& s_Property);
/**
* GetClientList - Get the list of clients attached to display.
*/
bool GetClientList(Display *disp,vector<Window>& v_wClientList);
/**
* GetWindowTitle - Get Window Title given Window ID
*/
bool GetWindowTitle(Display *disp, Window win, string& s_WindowTitle);
/**
* FindWindowMatching - Return first Window ID matching a title fragment.
*/
bool FindWindowMatching(Display *disp, string windowName, Window& win);
}
#endif
any ideas???

I'm going to be whiddling through this until it works....
looks like i'm just mangling things a bit...
-Thom