0
votes

I am creating a terminal application in gtk+ using vte. When I create a tab and add it to the notebook using the ctrl+t key combination it adds the tab with a new terminal in the tab as expected. However, the keypress signal also makes it through to the terminal and shows up as a "^T" before the command prompt along with a system beep. How do I use the keypress signal at the window level, so I can add the tab, but then block this specific keypress signal at the terminal level? Here is a block of code which shows how it is all assembled:

  window_main = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  vte = vte_terminal_new();
  terminal = VTE_TERMINAL (vte);

  notebook = gtk_notebook_new ();

  vbox = gtk_vbox_new(FALSE,0);
  gtk_container_add (GTK_CONTAINER (window_main), vbox);
  gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);  

  scrollwin[0] = gtk_scrolled_window_new (NULL, terminal->adjustment);
  gtk_container_add(GTK_CONTAINER(scrollwin[0]),vte);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin[0]), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

  label = gtk_label_new ("term1");
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), scrollwin[0], label);

Thanks.

1
Returning true from your signal handler doesn't do it?ergosys
@ergosys, thank you for your comment. However, I have to claim ignorance when it comes to signal handlers. It is time to learn. I've read about how to get the handler id, and I've also read about how to block signals using g_signal_handler_block but that seems like overkill. Which signal handler would I return true from? At which level to only block the signal from reaching the terminal, not the window? An example would be really helpful. I've been looking, but I can't find one. Thanks.nomadicME
I'm not sure I can help with that, but it would be useful to know how you are getting the ctrl-t in the first place.ergosys
@ergosys, you question is quite unclear, but I will do my best. First I hit the key combination ctrl+t, then I have a g_signal_connect statement that connects the key_press_event, for the main window, with the function to handle these key presses. Since the terminal by definition requires key presses to operate, this ctrl+t signal is also sent to the terminal where it registers as: ^T (the case is interesting because the caps lock is off). Anyway, hopefully that explains it.nomadicME
As I understand it, windows get first crack at keypress signals, then they go up the focus chain. So if you return true from that function when you handle ctrl-t (or any other keypress you don't want to propagate), it should keep it from going to the term widget.ergosys

1 Answers

1
votes

Windows get first crack at keypress events, then they go up the focus chain. Any signal handler returning true stops this propagation. So if you return true from your keypress signal handler when you handle ctrl-t (or any other keypress you don't want to propagate), it should keep it from going to the term widget.