replace GList with vector
This commit is contained in:
parent
6137340f6d
commit
189c669920
48
termite.cc
48
termite.cc
|
@ -3,6 +3,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
@ -63,7 +64,7 @@ struct keybind_info {
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *browser_cmd[3] = {NULL};
|
static char *browser_cmd[3] = {NULL};
|
||||||
GList *url_list = nullptr;
|
std::vector<url_data> url_list;
|
||||||
|
|
||||||
static void launch_browser(char *url);
|
static void launch_browser(char *url);
|
||||||
|
|
||||||
|
@ -107,19 +108,19 @@ static void find_urls(VteTerminal *vte) {
|
||||||
|
|
||||||
g_regex_match_full(regex, token, -1, 0, (GRegexMatchFlags)0, &info, &error);
|
g_regex_match_full(regex, token, -1, 0, (GRegexMatchFlags)0, &info, &error);
|
||||||
while (g_match_info_matches(info)) {
|
while (g_match_info_matches(info)) {
|
||||||
url_data *node = (url_data *)g_malloc(sizeof(url_data));
|
url_data node;
|
||||||
|
|
||||||
node->url = g_match_info_fetch(info, 0);
|
node.url = g_match_info_fetch(info, 0);
|
||||||
node->line = line;
|
node.line = line;
|
||||||
g_match_info_fetch_pos(info, 0, &node->pos, NULL);
|
g_match_info_fetch_pos(info, 0, &node.pos, NULL);
|
||||||
|
|
||||||
char c = token[node->pos];
|
char c = token[node.pos];
|
||||||
token[node->pos] = '\0';
|
token[node.pos] = '\0';
|
||||||
size_t len = mbstowcs(NULL, token, 0);
|
size_t len = mbstowcs(NULL, token, 0);
|
||||||
token[node->pos] = c;
|
token[node.pos] = c;
|
||||||
node->pos = len;
|
node.pos = len;
|
||||||
|
|
||||||
url_list = g_list_append(url_list, node);
|
url_list.push_back(node);
|
||||||
g_match_info_next(info, &error);
|
g_match_info_next(info, &error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,9 +135,8 @@ static void find_urls(VteTerminal *vte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void launch_url(unsigned id) {
|
static void launch_url(unsigned id) {
|
||||||
url_data *url = (url_data *)g_list_nth_data(url_list, id);
|
if (id < url_list.size()) {
|
||||||
if (url) {
|
browser_cmd[1] = url_list[id].url;
|
||||||
browser_cmd[1] = url->url;
|
|
||||||
g_spawn_async(NULL, (gchar **)browser_cmd, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
g_spawn_async(NULL, (gchar **)browser_cmd, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||||
} else {
|
} else {
|
||||||
g_printerr("url not found\n");
|
g_printerr("url not found\n");
|
||||||
|
@ -162,9 +162,7 @@ static void draw_marker(cairo_t *cr, glong x, glong y, unsigned id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean draw_cb(GtkDrawingArea *, cairo_t *cr, VteTerminal *vte) {
|
static gboolean draw_cb(GtkDrawingArea *, cairo_t *cr, VteTerminal *vte) {
|
||||||
if (url_list) {
|
if (!url_list.empty()) {
|
||||||
GList *l = url_list;
|
|
||||||
|
|
||||||
glong cols = vte_terminal_get_column_count(vte);
|
glong cols = vte_terminal_get_column_count(vte);
|
||||||
glong cw = vte_terminal_get_char_width(vte);
|
glong cw = vte_terminal_get_char_width(vte);
|
||||||
glong ch = vte_terminal_get_char_height(vte);
|
glong ch = vte_terminal_get_char_height(vte);
|
||||||
|
@ -173,16 +171,15 @@ static gboolean draw_cb(GtkDrawingArea *, cairo_t *cr, VteTerminal *vte) {
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||||
cairo_stroke(cr);
|
cairo_stroke(cr);
|
||||||
|
|
||||||
unsigned offset = 0, id = 1;
|
unsigned offset = 0;
|
||||||
|
|
||||||
for (; l != NULL; l = l->next, ++id) {
|
for (unsigned i = 0; i < url_list.size(); i++) {
|
||||||
url_data *data = (url_data *)l->data;
|
url_data data = url_list[i];
|
||||||
|
glong x = data.pos % cols * cw;
|
||||||
|
offset += data.pos / cols;
|
||||||
|
glong y = (data.line + offset) * ch;
|
||||||
|
|
||||||
glong x = data->pos % cols * cw;
|
draw_marker(cr, x, y, i + 1);
|
||||||
offset += data->pos / cols;
|
|
||||||
glong y = (data->line + offset) * ch;
|
|
||||||
|
|
||||||
draw_marker(cr, x, y, id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,8 +601,7 @@ gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, search_panel_in
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (info->mode == overlay_mode::urlselect) {
|
if (info->mode == overlay_mode::urlselect) {
|
||||||
gtk_widget_hide(info->da);
|
gtk_widget_hide(info->da);
|
||||||
g_list_free(url_list);
|
url_list.clear();
|
||||||
url_list = nullptr;
|
|
||||||
}
|
}
|
||||||
info->mode = overlay_mode::hidden;
|
info->mode = overlay_mode::hidden;
|
||||||
gtk_widget_hide(info->panel);
|
gtk_widget_hide(info->panel);
|
||||||
|
|
Loading…
Reference in New Issue