Get an X window ID

eberrocal at laurel.datsi.fi.upm.es eberrocal at laurel.datsi.fi.upm.es
Thu May 24 06:49:25 PDT 2007


Hi list.

Ok, I have found the problem of my segmentation fault and I have wrote a
function that get the ID of a new created window.

For me the solution is enough but I know that can be wrong if a window of
other application is created at the same time that the window I need to
capture.

I am going to put the code if somebody would want to watch it.

IN THE MAIN
===========

pid = fork();

switch(pid)
{
	case 0:
		if (execl("./app","./app","params",NULL) < 0)
				perror("execl");
			break;
	case -1:
		perror("fork");
		break;
	default:
		win_id = getIdNewWindow(display); // the ID of the new window

                [....]

		// wait for son
		while (pid != wait(NULL));
		fprintf(stdout, "Execution finished\n");
}

THE FUNCTION
============

Window getIdNewWindow (Display *display) {

	Window root_win, parent_win;
	Window *children_return;
        Window TheId;
	int n_children, screen_num;

	screen_num = DefaultScreen(display);
	root_win = getIDroot(display,screen_num);

	if (XQueryTree(display, root_win, &root_win, &parent_win,
		&children_return, &n_children) == False)
			return -1;

	children_return = children_return + (n_children - 1);

        TheId = *children_return;
        XFree(children_return);
	return TheId;

}

-------------------

Thank you for asking my questions. Now I can continue working in this way.
Sorry if my writing English is strange :)

Edu.






More information about the xorg mailing list