You are not logged in.
I'm currently trying to replicate Openbox's pipemenu capabilities with compiz-deskmenu using the current xml parser it uses (GMarkupParser) as something slightly different (pipe items, which can be inserted along side normal entries). Because of the way GMarkupParser parses xml, I thought I would just have to edit the context on the fly or preparse the menu, adding the entries as necessary. There are two ideas I currently have, but both have their own problems, along with one common problem:
The <pipe></pipe> approach: This will need to insert the pipe's generated items/menus/etc. in between the tags, allowing the program to clear anything between the <pipe> tags before re-editing the menu in memory.
The <item type="pipe"/> approach: This will need to insert the pipe's generated items just below the pipe item, but the entries generated by the pipe might need some identifier in order to for the program to recognize them and purge them.
Inserting the entries into the right position: g_string_insert() seems to fulfill what I need in order to edit the parser's context dynamically, but the problem with it is that it requires a gssize variable (which I assume is how many characters along the program is looking at). The function g_markup_parse_context_get_position (), on the other hand, prints out the line number and character number GMarkupParser was looking at. There's three possible remedies for this, although I'm not sure which one is more practical.
Solution 1 (most ideal, but I don't know any functions that might serve this): Find a way to get the program to report back where it's looking at as a gssize variable instead of line and column, possibly not related to GMarkupParser.
Solution 2 (could be difficult, but it might be more practical): Recode the program to use libxml2 and use a tree-like approach to generating the items (which is how openbox does it).
Solution 3 (could be easily implemented, but I have no idea how this would work): Get the program to parse the stdout of the pipe as a context for a while, then resume normally. A placeholder for the spat out pipeitem entries might be necessary.
There are probably some other functions I didn't look at that could edit the context on the fly, or some other usages of some of the GMarkupParser functions that could serve this purpose. Which of the solutions would be more practical to implement, and why? If there's any other functions I forgot that could be used to generated the pipeitems and parse them normally, please do tell.
[EDIT]: I'm trying #3, but somehow the pipe function can't access the parser variable even though it's static (I commented it out for now until I can get it to work). http://pastebin.com/pLuUgWsT <- the file so far, with the lines involving the parser variable and pipes highlighted.
[EDITEDIT] #3 doesn't work...so...back to solutions 1 & 2 for testing.
[EDITEDITEDIT] I figured out how to do this now: split the stream into chunks, each pipeitem with its own chunk. Then replace the pipeitem's chunk with its command output. Sorry if this was troublesome, but I hope it helps others trying to do the same.
Last edited by ShadowKyogre (2010-11-13 21:40:01)
For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page
Offline