xiterm

simple vte terminal emulator
git clone https://git.ce9e.org/xiterm.git

commit
7bd54cd3b5c5ed952db8de070b806a51f9cbb2c6
parent
d0b419259f034b85a5eda512a7b62d7e731c77c3
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-09-19 13:57
do not use GtkApplication

The architecture with GtkApplication is to have a single process with
several windows. When a user is starting a new instance all it does is
tell the existing process to add new window.

Since I did not know that the current implementation is buggy:

-	When one window is closed, the whole application quits and all of its
	windows are closed along with it.
-	Additional windows are not raised on creation.

To fix this I would have to change the code to not use the global window
and notebook variables.

As far as I could find out, the "old" approach to have one process per
instance is not deprecated and just simpler to reason about. So I prefer
to do that.

https://developer.gnome.org/GtkApplication/
https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased

Diffstat

M xiterm.c 36 +++++++++++++++---------------------

1 files changed, 15 insertions, 21 deletions


diff --git a/xiterm.c b/xiterm.c

@@ -7,7 +7,6 @@
    7     7 #define REGEX_URL "https?://[a-zA-Z0-9./_-]+"
    8     8 #define KEY(v, s) (event->keyval == (v) && event->state == (GDK_CONTROL_MASK|(s)))
    9     9 
   10    -1 GtkApplication *app;
   11    10 GtkWindow *window;
   12    11 GtkNotebook *notebook;
   13    12 VteRegex *url_regex;
@@ -173,15 +172,26 @@ gboolean on_key(GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
  173   172 	return TRUE;
  174   173 }
  175   174 
  176    -1 void activate(GtkApplication* app, gpointer user_data) {
   -1   175 int main(int argc, char **argv) {
   -1   176 	int i;
   -1   177 	GError *err = NULL;
  177   178 	GtkWidget *widget;
  178   179 
  179    -1 	widget = gtk_application_window_new(app);
   -1   180 	url_regex = vte_regex_new_for_match(REGEX_URL, -1, PCRE2_MULTILINE, &err);
   -1   181 	g_assert(err == NULL);
   -1   182 
   -1   183 	for (i = 0; i < 16; i++) {
   -1   184 		gdk_rgba_parse(palette + i, colors[i]);
   -1   185 	}
   -1   186 
   -1   187 	gtk_init(&argc, &argv);
   -1   188 	widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  180   189 	window = GTK_WINDOW(widget);
  181   190 	gtk_window_set_default_icon_name("utilities-terminal");
  182   191 	gtk_window_set_default_size(window, 620, 340);
  183   192 	gtk_window_set_title(window, "XiTerm");
  184   193 	g_signal_connect(GTK_WIDGET(window), "key-press-event", G_CALLBACK(on_key), NULL);
   -1   194 	g_signal_connect(GTK_WIDGET(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
  185   195 
  186   196 	widget = gtk_notebook_new();
  187   197 	gtk_container_add(GTK_CONTAINER(window), widget);
@@ -191,24 +201,8 @@ void activate(GtkApplication* app, gpointer user_data) {
  191   201 	gtk_widget_show_all(GTK_WIDGET(window));
  192   202 
  193   203 	add_tab();
  194    -1 }
  195    -1 
  196    -1 int main(int argc, char **argv) {
  197    -1 	int i, status;
  198    -1 	GError *err = NULL;
  199    -1 
  200    -1 	url_regex = vte_regex_new_for_match(REGEX_URL, -1, PCRE2_MULTILINE, &err);
  201    -1 	g_assert(err == NULL);
  202    -1 
  203    -1 	for (i = 0; i < 16; i++) {
  204    -1 		gdk_rgba_parse(palette + i, colors[i]);
  205    -1 	}
  206    -1 
  207    -1 	app = gtk_application_new("org.xi.xiterm", G_APPLICATION_FLAGS_NONE);
  208    -1 	g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
  209    -1 	status = g_application_run(G_APPLICATION(app), argc, argv);
  210    -1 	g_object_unref(app);
   -1   204 	gtk_main();
  211   205 	vte_regex_unref(url_regex);
  212   206 
  213    -1 	return status;
   -1   207 	return 0;
  214   208 }