📜 ⬆️ ⬇️

gnome-terminal Closing a tab with the middle mouse button

Good day, dear Habrovchane!

As they say it was in the evening at the end of the working day, there was nothing to do.

It seemed convenient to me to close the tabs in the browser with the middle mouse button and whether the lack of work or just sports interest, I decided to implement this in gnome-terminal.
Not that I missed the hotkeys, I just wanted the opportunity to be, much less to ask for it.
If you're wondering how this happened and what problems I ran into, welcome to cat.

Start


Armed with coffee, I went to look for gnome-terminal sources. Google vigorously issued the first reference source .
')
After downloading the latest version of the terminal (I think, and why is it trifling ..) I was broken off, I could not compile it :(

Spitting on this case, I downloaded the version of the current terminal installed in the system (2.33.0), which was successfully compiled. I started my "research".

Debriefing source



My knowledge of GTK is very superficial, so I hoped for readability of the code and started to study the source code for good luck.

In the course of viewing the files, I found terminal-tab-label.c, it seemed to me interesting and when I found the creation of the close tab button there I decided that I was in the right place.

A bit of screaming documentation (a little upset by the fact that in the documentation a bunch of broken links), I realized that in order to catch a mouse click on the label, you need to insert the following code:
g_signal_connect (label, "button-press-event", G_CALLBACK (click_label_cb), tab_label); 

But I was disappointed, the event did not handle.

The documentation also said: “To receive the GDK_BUTTON_PRESS_MASK mask.

Well, if you need, it means you need. By the method of searching and partial analysis of the code, I everywhere added lines like:
 gdk_window_set_events(root_window, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK); 

But once again it was broken off, there was no effect. Although there is still a plus. During the search for the main window, I came across an interesting function of the terminal_window_init (terminal-window.c), namely the line:
  g_signal_connect (priv->notebook, "button-press-event", G_CALLBACK (notebook_button_press_cb), window); 

In the end, I tried wedged in there.
A little fiddling, I came to this decision:
 .... static gboolean notebook_button_press_cb (GtkWidget *widget, GdkEventButton *event, TerminalWindow *window) { TerminalWindowPrivate *priv = window->priv; GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkWidget *menu; GtkAction *action; int tab_clicked; //   . if (event->type == GDK_BUTTON_PRESS && event->button == 2 ){ tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root); if (tab_clicked < 0) return FALSE; /* switch to the page the mouse is over */ gtk_notebook_set_current_page (notebook, tab_clicked); action = gtk_action_group_get_action (priv->action_group, "PopupCloseTab"); gtk_action_activate (action); return TRUE; } //   . if (event->type != GDK_BUTTON_PRESS || ..... 

Well that's all! Works!

Little things



Inspired by the success, I decided “at the same time” to remove one annoying trifle (confirmation to close the tab, if something is running), through the code I came across the line:
 do_confirm = gconf_client_get_bool (client, CONF_GLOBAL_PREFIX "/confirm_window_close", NULL); 

A little googling on gconf_client_get_bool I found in my configuration file in ~ / .gconf / apps / gnome-terminal.
Having established the necessary property (or maybe not quite correctly installed), this did not give, unfortunately, the necessary
effect. So I decided to go further.

In the source I found the installation confirm_window_close in two places gnome-terminal.schemas and gnome-terminal.schemas.in
It looks like this:
  <schema> <key>/schemas/apps/gnome-terminal/global/confirm_window_close</key> <applyto>/apps/gnome-terminal/global/confirm_window_close</applyto> <owner>gnome-terminal</owner> <type>bool</type> <default>true</default> <gettext_domain>gnome-terminal</gettext_domain> <locale name="C"> <short>Whether to ask for confirmation when closing terminal windows</short> <long>Whether to ask for confirmation when closing a terminal window which has more than one open tab.</long> </locale> </schema> 


By changing the default value to false it all worked. Hooray!

Well, then you need to install the changes we made, you can do it either by building the package (recommended) and install it, or make install (not recommended)

I apologize in advance for the confused style of presentation.
Thank you for attention!

Source: https://habr.com/ru/post/122571/


All Articles