From ee6dad5251b4d4fbad5575af89fb26100bcc8c62 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Thu, 9 Nov 2023 02:33:39 +0000 Subject: [PATCH 1/2] Use gtk_init_check. Also check for the X11 function we call in configure.ac. --- configure.ac | 2 +- src/gtkinterface.cc | 14 +------------- src/gtkinterface.h | 2 -- src/options.cc | 3 +-- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index dcc35c9..2fa669c 100644 --- a/configure.ac +++ b/configure.ac @@ -92,7 +92,7 @@ dnl We need libX11 dnl AC_DEFUN([AC_X11_REQUIREMENTS], [ - AC_CHECK_LIB(X11, XOpenDisplay) + AC_CHECK_LIB(X11, XInitThreads) X11_LIBS='-lX11' AC_SUBST(X11_LIBS) ]) diff --git a/src/gtkinterface.cc b/src/gtkinterface.cc index 6e53a2f..530f373 100644 --- a/src/gtkinterface.cc +++ b/src/gtkinterface.cc @@ -84,17 +84,6 @@ window_state_event_cb (GtkWidget *widget, return gtk_interface->handle_window_state_event (ws_event); } -bool -GtkInterface::have_x11_display() -{ - static Display *display = NULL; - - if (!display) - display = XOpenDisplay (NULL); // this should work if and only if we do have an X11 server we can use - - return display != NULL; -} - GtkInterface::GtkInterface() : window_xid (0), video_width (0), @@ -110,9 +99,8 @@ GtkInterface::init (int *argc, char ***argv, KeyHandler *handler) { key_handler = handler; - if (have_x11_display()) + if (gtk_init_check (argc, argv)) { - gtk_init (argc, argv); gtk_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_icon_name (GTK_WINDOW (gtk_window), "multimedia-player"); g_signal_connect (G_OBJECT (gtk_window), "key-press-event", G_CALLBACK (key_press_event_cb), this); diff --git a/src/gtkinterface.h b/src/gtkinterface.h index abdafe1..8f40b29 100644 --- a/src/gtkinterface.h +++ b/src/gtkinterface.h @@ -70,8 +70,6 @@ class GtkInterface void normal_size(); void set_opacity (double alpha_change); void set_title (const std::string& title); - - static bool have_x11_display(); }; #endif diff --git a/src/options.cc b/src/options.cc index 3be7dd0..046ae4b 100644 --- a/src/options.cc +++ b/src/options.cc @@ -105,8 +105,7 @@ Options::parse (int argc, char **argv) }; g_option_context_add_main_entries (context, all_options, NULL); g_option_context_add_group (context, gst_init_get_option_group()); - - if (GtkInterface::have_x11_display()) + if (gtk_init_check (&argc, &argv)) g_option_context_add_group (context, gtk_get_option_group (TRUE)); GError *error = NULL; From d15d9d2dfbb179d23ab7c985ba2f95653e13a8ce Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Thu, 9 Nov 2023 02:42:49 +0000 Subject: [PATCH 2/2] Force use of gdk's X11 backend. This doesn't work on wayland yet. --- src/gtkinterface.cc | 1 + src/options.cc | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/gtkinterface.cc b/src/gtkinterface.cc index 530f373..97eb66e 100644 --- a/src/gtkinterface.cc +++ b/src/gtkinterface.cc @@ -99,6 +99,7 @@ GtkInterface::init (int *argc, char ***argv, KeyHandler *handler) { key_handler = handler; + gdk_set_allowed_backends ("x11"); if (gtk_init_check (argc, argv)) { gtk_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); diff --git a/src/options.cc b/src/options.cc index 046ae4b..afb3fd3 100644 --- a/src/options.cc +++ b/src/options.cc @@ -105,6 +105,8 @@ Options::parse (int argc, char **argv) }; g_option_context_add_main_entries (context, all_options, NULL); g_option_context_add_group (context, gst_init_get_option_group()); + + gdk_set_allowed_backends("x11"); if (gtk_init_check (&argc, &argv)) g_option_context_add_group (context, gtk_get_option_group (TRUE));