Wrap the entry in a Gtk alignment and wire it up.
Should be functionally equivalent to the old code. There are still some strange focus issues.
This commit is contained in:
parent
18529b7b95
commit
2df3250792
85
termite.c
85
termite.c
|
@ -13,12 +13,11 @@
|
|||
# define __attribute__(x)
|
||||
#endif
|
||||
|
||||
typedef struct search_dialog_info {
|
||||
typedef struct search_panel_info {
|
||||
GtkWidget *vte;
|
||||
GtkWidget *entry;
|
||||
GtkBin *panel;
|
||||
bool reverse;
|
||||
bool open;
|
||||
} search_dialog_info;
|
||||
} search_panel_info;
|
||||
|
||||
static void search(VteTerminal *vte, const char *pattern, bool reverse) {
|
||||
GRegex *regex = vte_terminal_search_get_gregex(vte);
|
||||
|
@ -34,49 +33,16 @@ static void search(VteTerminal *vte, const char *pattern, bool reverse) {
|
|||
vte_terminal_copy_primary(vte);
|
||||
}
|
||||
|
||||
static void search_response_cb(GtkWidget *dialog, gint response_id, search_dialog_info *info) {
|
||||
if (response_id == GTK_RESPONSE_ACCEPT) {
|
||||
search(VTE_TERMINAL(info->vte), gtk_entry_get_text(GTK_ENTRY(info->entry)), info->reverse);
|
||||
}
|
||||
gtk_widget_destroy(dialog);
|
||||
info->open = false;
|
||||
}
|
||||
|
||||
static gboolean search_key_press_cb(__attribute__((unused)) GtkEntry *entry, GdkEventKey *event, GtkDialog *dialog) {
|
||||
static gboolean search_key_press_cb(GtkEntry *entry, GdkEventKey *event, search_panel_info *info) {
|
||||
if (event->keyval == GDK_KEY_Return) {
|
||||
gtk_dialog_response(dialog, GTK_RESPONSE_ACCEPT);
|
||||
search(VTE_TERMINAL(info->vte), gtk_entry_get_text(GTK_ENTRY(entry)), info->reverse);
|
||||
gtk_widget_hide(GTK_WIDGET(info->panel));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void open_search_dialog(GtkWidget *vte, bool reverse, search_dialog_info *info) {
|
||||
info->reverse = reverse;
|
||||
|
||||
if (info->open) {
|
||||
return;
|
||||
}
|
||||
|
||||
info->open = true;
|
||||
info->entry = gtk_entry_new();
|
||||
|
||||
GtkWidget *dialog, *content_area;
|
||||
dialog = gtk_dialog_new_with_buttons("Search",
|
||||
GTK_WINDOW(gtk_widget_get_toplevel(vte)),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
g_signal_connect(dialog, "response", G_CALLBACK(search_response_cb), info);
|
||||
g_signal_connect(info->entry, "key-press-event", G_CALLBACK(search_key_press_cb), dialog);
|
||||
|
||||
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||
gtk_container_add(GTK_CONTAINER(content_area), info->entry);
|
||||
gtk_widget_show_all(dialog);
|
||||
gtk_widget_grab_focus(GTK_WIDGET(info->entry));
|
||||
}
|
||||
|
||||
static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event, search_dialog_info *info) {
|
||||
static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event, search_panel_info *info) {
|
||||
const GdkModifierType modifiers = event->state & gtk_accelerator_get_default_mod_mask();
|
||||
if (modifiers == (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) {
|
||||
switch (gdk_keyval_to_lower(event->keyval)) {
|
||||
|
@ -95,10 +61,12 @@ static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event, search_dialog_i
|
|||
vte_terminal_copy_primary(VTE_TERMINAL(vte));
|
||||
return TRUE;
|
||||
case KEY(KEY_SEARCH):
|
||||
open_search_dialog(vte, false, info);
|
||||
info->reverse = false;
|
||||
gtk_widget_show(GTK_WIDGET(info->panel));
|
||||
return TRUE;
|
||||
case KEY(KEY_RSEARCH):
|
||||
open_search_dialog(vte, true, info);
|
||||
info->reverse = true;
|
||||
gtk_widget_show(GTK_WIDGET(info->panel));
|
||||
return TRUE;
|
||||
case KEY(KEY_URL):
|
||||
search(VTE_TERMINAL(vte), url_regex, false);
|
||||
|
@ -164,7 +132,7 @@ static void window_title_cb(VteTerminal *vte, GtkWindow *window) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static gboolean position_overlay(GtkOverlay *overlay, GtkWidget *widget, GdkRectangle *alloc) {
|
||||
static gboolean position_overlay_cb(GtkOverlay *overlay, GtkWidget *widget, GdkRectangle *alloc) {
|
||||
GtkWidget *main_widget = gtk_bin_get_child(GTK_BIN(overlay));
|
||||
|
||||
GtkAllocation main_alloc;
|
||||
|
@ -251,16 +219,29 @@ int main(int argc, char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(overlay), vte);
|
||||
gtk_container_add(GTK_CONTAINER(window), overlay);
|
||||
GtkWidget *alignment = gtk_alignment_new(0, 0, 1, 1);
|
||||
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 5, 5, 5);
|
||||
gtk_overlay_add_overlay(GTK_OVERLAY(overlay), alignment);
|
||||
|
||||
GtkWidget *entry = gtk_entry_new();
|
||||
gtk_widget_set_halign(entry, GTK_ALIGN_START);
|
||||
gtk_widget_set_valign(entry, GTK_ALIGN_END);
|
||||
gtk_overlay_add_overlay(GTK_OVERLAY(overlay), entry);
|
||||
|
||||
g_signal_connect(vte, "child-exited", G_CALLBACK(gtk_main_quit), NULL);
|
||||
g_signal_connect(overlay, "get-child-position", G_CALLBACK(position_overlay), NULL);
|
||||
gtk_container_add(GTK_CONTAINER(alignment), entry);
|
||||
gtk_container_add(GTK_CONTAINER(overlay), vte);
|
||||
gtk_container_add(GTK_CONTAINER(window), overlay);
|
||||
|
||||
search_panel_info info = {
|
||||
.vte = vte,
|
||||
.panel = GTK_BIN(alignment),
|
||||
.reverse = false
|
||||
};
|
||||
|
||||
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
g_signal_connect(vte, "child-exited", G_CALLBACK(gtk_main_quit), NULL);
|
||||
g_signal_connect(vte, "key-press-event", G_CALLBACK(key_press_cb), &info);
|
||||
g_signal_connect(entry, "key-press-event", G_CALLBACK(search_key_press_cb), &info);
|
||||
g_signal_connect(overlay, "get-child-position", G_CALLBACK(position_overlay_cb), NULL);
|
||||
|
||||
vte_terminal_set_scrollback_lines(VTE_TERMINAL(vte), scrollback_lines);
|
||||
vte_terminal_set_font_from_string(VTE_TERMINAL(vte), font);
|
||||
|
@ -301,11 +282,6 @@ int main(int argc, char **argv) {
|
|||
|
||||
vte_terminal_set_colors(VTE_TERMINAL(vte), &foreground, &background, palette, 16);
|
||||
|
||||
search_dialog_info info = { .vte = vte, .open = false };
|
||||
|
||||
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
g_signal_connect(vte, "key-press-event", G_CALLBACK(key_press_cb), &info);
|
||||
|
||||
#ifdef CLICKABLE_URL
|
||||
int tmp = vte_terminal_match_add_gregex(VTE_TERMINAL(vte),
|
||||
g_regex_new(url_regex,
|
||||
|
@ -329,6 +305,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
gtk_widget_grab_focus(vte);
|
||||
gtk_widget_show_all(window);
|
||||
gtk_widget_hide(alignment);
|
||||
gtk_main();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue