thestinger/termite — pull request #16 by vodik (2012-06-04 23:53:51+00:00)
Title: URL Hinting Support

**NOTE: This is a proof of concept and *not* ready to be merged just yet! Furthermore, ``scrollback-completion`` should first be merged in.**

Okay, I'm writing this to demonstrate a proof of concept URL hinting overlay and would like some feedback. This *works*, I can launch the overlay, have it accurately find URLs, and launch them.

There are still parts that are lacking, this code needs lots of refactoring, leaks memory since I never free anything, and has *lots* of rendering quirks.

The approach I take is to get the vte's content, tokenize it across newlines, and for each token search for URLs with regular expressions. When a URL is found, find its offset and store it all in a big linked list that the drawing and launching code can use to figure out where and what things are.

To find the correct offset to account for unicode characters, I do the following:

```
g_match_info_fetch_pos(info, 0, &node->pos, NULL);

char c = token[node->pos];
token[node->pos] = '\0';
size_t len = mbstowcs(NULL, token, 0);
token[node->pos] = c;
node->pos = len;
```

This will work as long as ``'\0'`` isn't valid character in the vte's text, but if it did show up, it would break ``strtok_r`` first.

Another big issue is with how the overlay itself works. The underlying vte doesn't lock and still accepts keyboard input, but stops accepting mouse input (the drawing area hosting the hints is in the way). The second there's a newline, the overlay becomes misaligned.

It completely breaks down when transparency is enabled. Gtk doesn't seem to like overlaying transparencies, what ends up happening is the vte disappears and the URL hints appear over a fully transparent window without any other content visible.

The right solution for this I would assume would be *not* to have a transparent overlay with the hints on it but to actually copy the vte's pixmap onto the overlay and then draw over that, but I'm worried that this would also break transparency support.

Suggestions, comments, and patches welcome.