Remove X11 Dependency

This commit is contained in:
TheBrokenRail 2022-03-11 18:09:14 -05:00
parent 6f08afb798
commit 4663a8656d
7 changed files with 4 additions and 119 deletions

View File

@ -19,10 +19,6 @@ pkg_check_modules(GTK3 REQUIRED IMPORTED_TARGET "gtk+-3.0>=3.16.0")
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET "glib-2.0>=2.43.4") pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET "glib-2.0>=2.43.4")
link_libraries(PkgConfig::GTK3 PkgConfig::GLIB) link_libraries(PkgConfig::GTK3 PkgConfig::GLIB)
# X11
find_package(X11 REQUIRED)
link_libraries(${X11_LIBRARIES})
# Build # Build
add_custom_command( add_custom_command(
OUTPUT ".gresource.c" OUTPUT ".gresource.c"

View File

@ -153,7 +153,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
g_object_unref (builder); g_object_unref (builder);
zenity_util_show_dialog (dialog, data->attach); zenity_util_show_dialog (dialog);
if (data->timeout_delay > 0) { if (data->timeout_delay > 0) {
g_timeout_add_seconds (data->timeout_delay, g_timeout_add_seconds (data->timeout_delay,

View File

@ -29,7 +29,6 @@
/* General Options */ /* General Options */
static gchar *zenity_general_dialog_title; static gchar *zenity_general_dialog_title;
static gchar *zenity_general_window_icon;
static int zenity_general_width; static int zenity_general_width;
static int zenity_general_height; static int zenity_general_height;
static gchar *zenity_general_dialog_text; static gchar *zenity_general_dialog_text;
@ -44,7 +43,6 @@ static gchar *zenity_general_ok_button;
static gchar *zenity_general_cancel_button; static gchar *zenity_general_cancel_button;
static gchar **zenity_general_extra_buttons; static gchar **zenity_general_extra_buttons;
static gboolean zenity_general_modal; static gboolean zenity_general_modal;
static guintptr zenity_general_attach;
/* Entry Dialog Options */ /* Entry Dialog Options */
static gboolean zenity_entry_active; static gboolean zenity_entry_active;
@ -69,13 +67,6 @@ static GOptionEntry general_options[] = {{"title",
&zenity_general_dialog_title, &zenity_general_dialog_title,
"Set the dialog title", "Set the dialog title",
"TITLE"}, "TITLE"},
{"window-icon",
'\0',
0,
G_OPTION_ARG_FILENAME,
&zenity_general_window_icon,
"Set the window icon",
"ICONPATH"},
{"width", {"width",
'\0', '\0',
0, 0,
@ -126,13 +117,6 @@ static GOptionEntry general_options[] = {{"title",
&zenity_general_modal, &zenity_general_modal,
"Set the modal hint", "Set the modal hint",
NULL}, NULL},
{"attach",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_INT,
&zenity_general_attach,
"Set the parent window to attach to",
"WINDOW"},
{NULL}}; {NULL}};
static GOptionEntry entry_options[] = {{"entry", static GOptionEntry entry_options[] = {{"entry",
@ -280,8 +264,6 @@ void
zenity_option_free (void) { zenity_option_free (void) {
if (zenity_general_dialog_title) if (zenity_general_dialog_title)
g_free (zenity_general_dialog_title); g_free (zenity_general_dialog_title);
if (zenity_general_window_icon)
g_free (zenity_general_window_icon);
if (zenity_general_dialog_text) if (zenity_general_dialog_text)
g_free (zenity_general_dialog_text); g_free (zenity_general_dialog_text);
if (zenity_general_uri) if (zenity_general_uri)
@ -341,7 +323,6 @@ static gboolean
zenity_general_pre_callback (GOptionContext *context, GOptionGroup *group, zenity_general_pre_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) { gpointer data, GError **error) {
zenity_general_dialog_title = NULL; zenity_general_dialog_title = NULL;
zenity_general_window_icon = NULL;
zenity_general_width = -1; zenity_general_width = -1;
zenity_general_height = -1; zenity_general_height = -1;
zenity_general_dialog_text = NULL; zenity_general_dialog_text = NULL;
@ -356,7 +337,6 @@ zenity_general_pre_callback (GOptionContext *context, GOptionGroup *group,
zenity_general_dialog_no_markup = FALSE; zenity_general_dialog_no_markup = FALSE;
zenity_general_timeout_delay = -1; zenity_general_timeout_delay = -1;
zenity_general_modal = FALSE; zenity_general_modal = FALSE;
zenity_general_attach = 0;
return TRUE; return TRUE;
} }
@ -394,7 +374,6 @@ static gboolean
zenity_general_post_callback (GOptionContext *context, GOptionGroup *group, zenity_general_post_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) { gpointer data, GError **error) {
results->data->dialog_title = zenity_general_dialog_title; results->data->dialog_title = zenity_general_dialog_title;
results->data->window_icon = zenity_general_window_icon;
results->data->width = zenity_general_width; results->data->width = zenity_general_width;
results->data->height = zenity_general_height; results->data->height = zenity_general_height;
results->data->timeout_delay = zenity_general_timeout_delay; results->data->timeout_delay = zenity_general_timeout_delay;
@ -402,7 +381,6 @@ zenity_general_post_callback (GOptionContext *context, GOptionGroup *group,
results->data->cancel_label = zenity_general_cancel_button; results->data->cancel_label = zenity_general_cancel_button;
results->data->extra_label = zenity_general_extra_buttons; results->data->extra_label = zenity_general_extra_buttons;
results->data->modal = zenity_general_modal; results->data->modal = zenity_general_modal;
results->data->attach = zenity_general_attach;
return TRUE; return TRUE;
} }

View File

@ -635,7 +635,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
gtk_tree_view_set_search_column (GTK_TREE_VIEW (tree_view), 1); gtk_tree_view_set_search_column (GTK_TREE_VIEW (tree_view), 1);
} }
zenity_util_show_dialog (dialog, data->attach); zenity_util_show_dialog (dialog);
if (tree_data->mid_search) if (tree_data->mid_search)
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (tree_view), gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (tree_view),

View File

@ -36,10 +36,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#define ZENITY_OK_DEFAULT 0 #define ZENITY_OK_DEFAULT 0
#define ZENITY_CANCEL_DEFAULT 1 #define ZENITY_CANCEL_DEFAULT 1
#define ZENITY_ESC_DEFAULT 1 #define ZENITY_ESC_DEFAULT 1
@ -244,93 +240,9 @@ zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *zen_data) {
zen_data->exit_code = zenity_util_return_exit_code (value); zen_data->exit_code = zenity_util_return_exit_code (value);
} }
#ifdef GDK_WINDOWING_X11
static Window
transient_get_xterm (void) {
const char *wid_str = g_getenv ("WINDOWID");
if (wid_str) {
char *wid_str_end;
int ret;
Window wid = strtoul (wid_str, &wid_str_end, 10);
if (*wid_str != '\0' && *wid_str_end == '\0' && wid != 0) {
XWindowAttributes attrs;
GdkDisplay *display;
display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
ret = XGetWindowAttributes (
GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wid, &attrs);
if (gdk_x11_display_error_trap_pop (display) != 0 || ret == 0) {
return None;
}
return wid;
}
}
return None;
}
static void
transient_x_free (void *ptr) {
if (ptr)
XFree (ptr);
}
static gboolean
transient_is_toplevel (Window wid) {
XTextProperty prop;
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
if (!XGetWMName (dpy, wid, &prop))
return FALSE;
transient_x_free (prop.value);
return !!prop.value;
}
/*
* GNOME Terminal doesn't give us its toplevel window, but the WM needs a
* toplevel XID for proper stacking. Other terminals work fine without this
* magic. We can't use GDK here since "xterm" is a foreign window.
*/
static Window
transient_get_xterm_toplevel (void) {
Window xterm = transient_get_xterm ();
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
while (xterm != None && !transient_is_toplevel (xterm)) {
Window root, parent, *children;
unsigned nchildren;
XQueryTree (dpy, xterm, &root, &parent, &children, &nchildren);
transient_x_free (children);
if (parent == root)
xterm = None;
else
xterm = parent;
}
return xterm;
}
static void
zenity_util_make_transient (GdkWindow *window, Window parent) {
Window parent_window = parent;
if (parent_window == 0)
parent_window = transient_get_xterm_toplevel ();
if (parent_window != None) {
XSetTransientForHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
GDK_WINDOW_XID (window),
parent_window);
}
}
#endif /* GDK_WINDOWING_X11 */
void void
zenity_util_show_dialog (GtkWidget *dialog, guintptr parent) { zenity_util_show_dialog (GtkWidget *dialog) {
gtk_widget_realize (dialog); gtk_widget_realize (dialog);
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
g_assert (gtk_widget_get_window (dialog));
zenity_util_make_transient (gtk_widget_get_window (dialog), parent);
}
#endif
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }

View File

@ -17,7 +17,7 @@ gboolean zenity_util_fill_file_buffer (
void zenity_util_show_help (GError **error); void zenity_util_show_help (GError **error);
gint zenity_util_return_exit_code (ZenityExitCode value); gint zenity_util_return_exit_code (ZenityExitCode value);
void zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *data); void zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *data);
void zenity_util_show_dialog (GtkWidget *widget, guintptr parent); void zenity_util_show_dialog (GtkWidget *widget);
gboolean zenity_util_timeout_handle (gpointer data); gboolean zenity_util_timeout_handle (gpointer data);

View File

@ -7,7 +7,6 @@ G_BEGIN_DECLS
typedef struct { typedef struct {
gchar *dialog_title; gchar *dialog_title;
gchar *window_icon;
gchar *ok_label; gchar *ok_label;
gchar *cancel_label; gchar *cancel_label;
gchar **extra_label; gchar **extra_label;