Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request thestinger#564 from 0xcpy/master
Browse files Browse the repository at this point in the history
Use std::make_unique from c++14
jelly authored Feb 11, 2018
2 parents 051e2fb + 8dd8f55 commit 7138bc4
Showing 2 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ GTK = gtk+-3.0
VTE = vte-2.91
TERMINFO = ${PREFIX}/share/terminfo

CXXFLAGS := -std=c++11 -O3 \
CXXFLAGS := -std=c++14 -O3 \
-Wall -Wextra -pedantic \
-Winit-self \
-Wshadow \
@@ -32,7 +32,7 @@ endif
LDFLAGS := -s -Wl,--as-needed ${LDFLAGS}
LDLIBS := ${shell pkg-config --libs ${GTK} ${VTE}}

termite: termite.cc url_regex.hh util/clamp.hh util/maybe.hh util/memory.hh
termite: termite.cc url_regex.hh util/clamp.hh util/maybe.hh
${CXX} ${CXXFLAGS} ${LDFLAGS} $< ${LDLIBS} -o $@

install: termite termite.desktop termite.terminfo
25 changes: 12 additions & 13 deletions termite.cc
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@
#include "url_regex.hh"
#include "util/clamp.hh"
#include "util/maybe.hh"
#include "util/memory.hh"

using namespace std::placeholders;

@@ -297,18 +296,18 @@ static void launch_in_directory(VteTerminal *vte) {
g_printerr("no directory uri set\n");
return;
}
auto dir = make_unique(g_filename_from_uri(uri, nullptr, nullptr), g_free);
auto dir = std::make_unique<gchar*>(g_filename_from_uri(uri, nullptr, nullptr));
char term[] = "termite"; // maybe this should be argv[0]
char *cmd[] = {term, nullptr};
g_spawn_async(dir.get(), cmd, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr);
g_spawn_async(*dir.get(), cmd, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr);
}

static void find_urls(VteTerminal *vte, search_panel_info *panel_info) {
GRegex *regex = g_regex_new(url_regex, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, nullptr);
GArray *attributes = g_array_new(FALSE, FALSE, sizeof(VteCharAttributes));
auto content = make_unique(vte_terminal_get_text(vte, nullptr, nullptr, attributes), g_free);
auto content = std::make_unique<gchar*>(vte_terminal_get_text(vte, nullptr, nullptr, attributes));

for (char *s_ptr = content.get(), *saveptr; ; s_ptr = nullptr) {
for (char *s_ptr = *content.get(), *saveptr; ; s_ptr = nullptr) {
const char *token = strtok_r(s_ptr, "\n", &saveptr);
if (!token) {
break;
@@ -323,7 +322,7 @@ static void find_urls(VteTerminal *vte, search_panel_info *panel_info) {
g_match_info_fetch_pos(info, 0, &pos, nullptr);

const long first_row = g_array_index(attributes, VteCharAttributes, 0).row;
const auto attr = g_array_index(attributes, VteCharAttributes, token + pos - content.get());
const auto attr = g_array_index(attributes, VteCharAttributes, token + pos - *content.get());

panel_info->url_list.emplace_back(g_match_info_fetch(info, 0),
attr.column,
@@ -570,9 +569,9 @@ static void open_selection(char *browser, VteTerminal *vte) {
}

if (browser) {
auto selection = make_unique(vte_terminal_get_selection(vte), g_free);
auto selection = std::make_unique<gchar*>(vte_terminal_get_selection(vte));
if (selection && *selection) {
launch_browser(browser, selection.get());
launch_browser(browser, *selection.get());
}
} else {
g_printerr("no browser to open url\n");
@@ -1183,21 +1182,21 @@ gboolean position_overlay_cb(GtkBin *overlay, GtkWidget *widget, GdkRectangle *a
gboolean button_press_cb(VteTerminal *vte, GdkEventButton *event, const config_info *info) {
if (info->clickable_url && event->type == GDK_BUTTON_PRESS) {
#if VTE_CHECK_VERSION (0, 49, 1)
auto match = make_unique(vte_terminal_hyperlink_check_event(vte, (GdkEvent*)event), g_free);
auto match = std::make_unique<gchar*>(vte_terminal_hyperlink_check_event(vte, (GdkEvent*)event));
if (!match) {
match = make_unique(check_match(vte, event), g_free);
match = std::make_unique<gchar*>(check_match(vte, event));
}
#else
auto match = make_unique(check_match(vte, event), g_free);
auto match = std::make_unique<gchar*>(check_match(vte, event));
#endif
if (!match)
return FALSE;

if (event->button == 1) {
launch_browser(info->browser, match.get());
launch_browser(info->browser, *match.get());
} else if (event->button == 3) {
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, match.get(), -1);
gtk_clipboard_set_text(clipboard, *match.get(), -1);
}

return TRUE;

0 comments on commit 7138bc4

Please sign in to comment.