Last active
October 5, 2022 01:31
-
-
Save huynp1999/04b8cdb08da8f4c1075c21cae258d1cb to your computer and use it in GitHub Desktop.
Enable google search option for gnome terminal 3.44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/terminal-util.cc b/src/terminal-util.cc | |
index b430efca..8b882ad9 100644 | |
--- a/src/terminal-util.cc | |
+++ b/src/terminal-util.cc | |
@@ -113,7 +113,7 @@ terminal_util_show_error_dialog (GtkWindow *transient_parent, | |
} | |
} | |
-static gboolean | |
+gboolean | |
open_url (GtkWindow *parent, | |
const char *uri, | |
guint32 user_time, | |
diff --git a/src/terminal-util.hh b/src/terminal-util.hh | |
index d980725e..91e4a2ff 100644 | |
--- a/src/terminal-util.hh | |
+++ b/src/terminal-util.hh | |
@@ -109,6 +109,12 @@ char *terminal_util_find_program_in_path (const char *path, | |
gboolean terminal_util_check_envv(char const* const* strv); | |
+gboolean | |
+open_url (GtkWindow *parent, | |
+ const char *uri, | |
+ guint32 user_time, | |
+ GError **error); | |
+ | |
G_END_DECLS | |
#endif /* TERMINAL_UTIL_H */ | |
diff --git a/src/terminal-window.cc b/src/terminal-window.cc | |
index 78fcbc1a..673dca98 100644 | |
--- a/src/terminal-window.cc | |
+++ b/src/terminal-window.cc | |
@@ -670,6 +670,29 @@ action_copy_cb (GSimpleAction *action, | |
vte_terminal_copy_clipboard_format (VTE_TERMINAL (priv->active_screen), format); | |
} | |
+static void | |
+action_google_cb (GSimpleAction *action, | |
+ GVariant *parameter, | |
+ gpointer user_data) | |
+{ | |
+ TerminalWindow *window = (TerminalWindow*)user_data; | |
+ TerminalWindowPrivate *priv = window->priv; | |
+ const char *format_str; | |
+ VteFormat format; | |
+ gchar *url; | |
+ GtkClipboard *clipboard; | |
+ | |
+ if (priv->active_screen == NULL) | |
+ return; | |
+ | |
+ g_assert_nonnull (parameter); | |
+ g_variant_get (parameter, "&s", &format_str); | |
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window), GDK_SELECTION_PRIMARY); | |
+ url = g_strdup_printf ("http://www.google.com/search?ie=UTF-8&q=%s", gtk_clipboard_wait_for_text(clipboard)); | |
+ open_url (GTK_WINDOW (window), url, gtk_get_current_event_time (), NULL); | |
+ g_free(url); | |
+} | |
+ | |
/* Clipboard helpers */ | |
typedef struct { | |
@@ -1774,6 +1797,7 @@ screen_show_popup_menu_cb (TerminalScreen *screen, | |
g_menu_append (section4, _("_Copy"), "win.copy::text"); | |
g_menu_append (section4, _("Copy as _HTML"), "win.copy::html"); | |
g_menu_append (section4, _("_Paste"), "win.paste-text"); | |
+ g_menu_append (section4, _("Search on Google"), "win.search-google::text"); | |
if (g_action_get_enabled (G_ACTION (lookup_action (window, "paste-uris")))) | |
g_menu_append (section4, _("Paste as _Filenames"), "win.paste-uris"); | |
@@ -2100,6 +2124,7 @@ terminal_window_init (TerminalWindow *window) | |
{ "paste-uris", action_paste_uris_cb, nullptr, nullptr, nullptr }, | |
{ "reset", action_reset_cb, "b", nullptr, nullptr }, | |
{ "select-all", action_select_all_cb, nullptr, nullptr, nullptr }, | |
+ { "search-google", action_google_cb, "s", NULL, NULL }, | |
{ "size-to", action_size_to_cb, "(uu)", nullptr, nullptr }, | |
{ "tab-detach", action_tab_detach_cb, nullptr, nullptr, nullptr }, | |
{ "tab-move-left", action_tab_move_left_cb, nullptr, nullptr, nullptr }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to apply patch:
Kill all current gnome-terminal to use new patched version.
Or