Question

I have two programs and I would like one to attach a structure to its window and the other one to read this structure. I have to use X.

I tried with XSaveContext and XFindContext. I managed to attach a structure to a window and read it afterward, in the same program.

Then I made a program that uses XSaveContext to attach a structure to its window. At the same time another program makes a list of all the window that opened and tries for each ones to find a structure

Saving context

XContext contextUserData = 100;
UserData data;
UserData *ptr_data = &data;

data.name = "app01 userdata name";
data.refNumber = 777;

XSaveContext(disp, win, contextUserData, XPointer(ptr_data));

std::cout<<"disp "<<disp<<" win "<<parent<<std::endl;

Finding context :

XContext contextUserData = 100;
UserData data_return;
UserData *ptr_data = &data_return;
XPointer xpointer = XPointer(ptr_data);
XPointer *xptr = &xpointer;

if (XFindContext(mDisplay(), allWin[i], contextUserData, (xptr)) == 0)
{
    ptr_data = (UserData*)(*xptr);
    std::cout<<"name : "<<ptr_data->name<<" refNumber : "<<ptr_data->refNumber<<std::endl;
}
else
{
    std::cout<<"disp "<<mDisplay()<<" win "<<allWin[i]<<" No info"<<std::endl;
}

the program that attach the structure displays this :

disp 0x983d488 win 33554435

and the program that looks for a structure display this :

disp 0x9f922f0 win 31457287 No info
disp 0x9f922f0 win 31457316 No info
disp 0x9f922f0 win 23137913 No info
disp 0x9f922f0 win 33554434 No info
disp 0x9f922f0 win 33554435 No info (the right window)
disp 0x9f922f0 win 23138015 No info

I test the right window but I don't get any result.

I wonder if XSaveContext and XFindContext have to be called with the same display to return the structure.

So my question is, how do I add personal data to a window and make it readable by other windows ?

Thank you.

Was it helpful?

Solution

You can't share data between two processes this way:

Note that this is local to your program; the data is not stored in the server on a property list

I'd suggest to use window properties as shared data storage

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top