Monday, June 4, 2007

Label Issues

I spent a good deal of time yesterday trying to figure out why a simple piece of code wouldn't work. I was working on the key binding stuff again. The way I want it to work is for the rebinding window to display the key combination caught to the user. When the window is first drawn it displays a label that contains 'KEY:""' (the single quote are for the reader and the double quotes actually appear in the label). Then when the user types in a combination it should update to 'KEY:"comb"', where comb is a human readable representation of the key combination entered by the user. Well, it's a pretty easy setup, you have a key_pressed listener that gets the label as an argument. A quick lookup to convert the keys received to a nicer format. Then a quick update to the label text and it should work nicely.

After several hours of staring at the code, quite a bit of research into the underlying code. I simply couldn't figure out why the label wouldn't update. I tried printing the keys out to stderr but something weird was happening there too. When I printed out the ASCII values one at a time, they came out nicely, as I would expect. But when I tried printing them out as a string, it printed blank. Well, come to find out, the problems with fprintf and label updating weren't related, they just happened to yield the same result. When we tried a quick test by executing printf("%s\n","\033" "a"), the equivalent to Alt-a, only a newline would print. So it was just a nuance of printf behavior. The issue with the label was different.

I spoke with my mentor for about an hour about this issue and finally he decided to pull the code and have a look for himself. He was taking too long, so at about 0030 I went to bed. He wrote back at 0200 saying he figured out what was wrong. It seems that when gnt_label_draw() was being called, it would first set an INVISIBLE flag, but failed to unset it before returning. It was a quick fix that required a lot of digging. So he fixed it and pushed it upstream. This morning I did a pull and merged his changes into mine and it worked.

Now we have issues with the label not redrawing nicely. But at least it's redrawing now. So I get to continue hacking away at this project.

No comments: