8000 Optionally disable X11-dependent modules by cemkeylan · Pull Request #259 · v1cont/yad · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optionally disable X11-dependent modules #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ if test x$have_html = xyes; then
AC_DEFINE([HAVE_HTML], [1], [Define this if you have webkit2gt library])
fi

dnl paned and notebook
AC_ARG_WITH([x11],
[AS_HELP_STRING([--with-x11],
[Build YAD modules that require x11 (notebook, paned)])],
[with_x11=$enableval], [with_x11=yes]
)
if test x$with_html = xyes; then
PKG_CHECK_MODULES([GTK_X11], [gtk+-x11-3.0], [with_x11=yes], [with_x11=no])
else
with_x11=no
fi
AM_CONDITIONAL([X11], [test x$with_x11 = xyes])

if test x$with_x11 = xyes; then
AC_DEFINE([HAVE_X11], [1], [Define this if you are using GTK+3 with X11 backend])
fi

dnl status icon widget
AC_ARG_ENABLE([tray],
[AS_HELP_STRING([--enable-tray],
Expand Down Expand Up @@ -168,6 +185,7 @@ echo " Status icon - $build_tray"
echo " HTML widget - $have_html"
echo " GtkSourceView - $have_sourceview"
echo " Spell checking - $have_spell"
echo " X11-only utilities - $with_x11"
echo " Path to rgb.txt - $with_rgb"
echo " Standalone build - $build_sa"
echo " Tools - $build_tools"
Expand Down
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ yad_SOURCES = \
form.c \
icons.c \
list.c \
notebook.c \
option.c \
paned.c \
picture.c \
print.c \
progress.c \
Expand All @@ -42,6 +40,10 @@ if HTML
yad_SOURCES += html.c
endif

if X11
yad_SOURCES += notebook.c paned.c
endif

if STANDALONE
yad_SOURCES += defaults.h
endif
Expand Down
28 changes: 24 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

#ifndef G_OS_WIN32
# include <sys/shm.h>
# include <gdk/gdkx.h>
#endif
#ifdef HAVE_X11
#include <gdk/gdkx.h>
#endif

#include "yad.h"
Expand Down Expand Up @@ -290,6 +292,7 @@ create_layout (GtkWidget *dlg)
case YAD_MODE_LIST:
mw = list_create_widget (dlg);
break;
#ifdef HAVE_X11
case YAD_MODE_NOTEBOOK:
if (options.plug == -1)
mw = notebook_create_widget (dlg);
Expand All @@ -298,6 +301,7 @@ create_layout (GtkWidget *dlg)
if (options.plug == -1)
mw = paned_create_widget (dlg);
break;
#endif
case YAD_MODE_PICTURE:
mw = picture_create_widget (dlg);
break;
Expand Down Expand Up @@ -612,6 +616,7 @@ create_dialog (void)
gtk_window_fullscreen (GTK_WINDOW (dlg));
}

#ifdef HAVE_X11
/* print xid */
if (is_x11 && options.print_xid)
{
Expand All @@ -632,6 +637,7 @@ create_dialog (void)
fflush (xf);
}
}
#endif

return dlg;
}
Expand All @@ -648,10 +654,12 @@ create_plug (void)
tabs = get_tabs (options.plug, FALSE);
}

#ifdef HAVE_X11
while (!tabs[0].xid)
usleep (1000);

win = gtk_plug_new (0);
#endif
/* set window borders */
if (options.data.borders == -1)
options.data.borders = (gint) gtk_container_get_border_width (GTK_CONTAINER (win));
Expand All @@ -666,7 +674,9 @@ create_plug (void)
/* add plug data */
/* notebook/paned will count non-zero xids */
tabs[options.tabnum].pid = getpid ();
#ifdef HAVE_X11
tabs[options.tabnum].xid = gtk_plug_get_id (GTK_PLUG (win));
#endif
shmdt (tabs);
}

Expand Down Expand Up @@ -699,12 +709,14 @@ yad_print_result (void)
case YAD_MODE_LIST:
list_print_result ();
break;
#ifdef HAVE_X11
case YAD_MODE_NOTEBOOK:
notebook_print_result ();
break;
case YAD_MODE_PANED:
paned_print_result ();
break;
#endif
case YAD_MODE_SCALE:
scale_print_result ();
break;
Expand Down Expand Up @@ -885,6 +897,7 @@ main (gint argc, gchar ** argv)
return ret;
}

#ifdef HAVE_X11
if (!is_x11)
{
if (options.mode == YAD_MODE_NOTEBOOK || options.mode == YAD_MODE_PANED
Expand All @@ -897,6 +910,7 @@ main (gint argc, gchar ** argv)
return 1;
}
}
#endif

switch (options.mode)
{
Expand All @@ -921,20 +935,24 @@ main (gint argc, gchar ** argv)
default:
dialog = create_dialog ();

#ifdef HAVE_X11
if (is_x11)
{
/* add YAD_XID variable */
str = g_strdup_printf ("0x%lX", GDK_WINDOW_XID (gtk_widget_get_window (dialog)));
g_setenv ("YAD_XID", str, TRUE);
}
#endif

/* make some specific init actions */
if (options.mode == YAD_MODE_NOTEBOOK)
if (options.mode == YAD_MODE_TEXTINFO)
text_goto_line ();
#ifdef HAVE_X11
else if (options.mode == YAD_MODE_NOTEBOOK)
notebook_swallow_childs ();
else if (options.mode == YAD_MODE_PANED)
paned_swallow_childs ();
else if (options.mode == YAD_MODE_TEXTINFO)
text_goto_line ();
#endif
else if (options.mode == YAD_MODE_PICTURE)
{
if (options.picture_data.size == YAD_PICTURE_FIT)
Expand Down Expand Up @@ -963,10 +981,12 @@ main (gint argc, gchar ** argv)
}
}
#ifndef G_OS_WIN32
#ifdef HAVE_X11
if (options.mode == YAD_MODE_NOTEBOOK)
notebook_close_childs ();
else if (options.mode == YAD_MODE_PANED)
paned_close_childs ();
#endif
/* autokill option for progress dialog */
if (!options.kill_parent)
{
Expand Down
26 changes: 23 additions & 3 deletions src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ static gboolean html_mode = FALSE;
#endif
static gboolean icons_mode = FALSE;
static gboolean list_mode = FALSE;
#ifdef HAVE_X11
static gboolean notebook_mode = FALSE;
static gboolean paned_mode = FALSE;
#endif
#ifdef HAVE_TRAY
static gboolean notification_mode = FALSE;
#endif
static gboolean paned_mode = FALSE;
static gboolean picture_mode = FALSE;
static gboolean print_mode = FALSE;
static gboolean progress_mode = FALSE;
Expand Down Expand Up @@ -519,6 +521,7 @@ static GOptionEntry list_options[] = {
{ NULL }
};

#ifdef HAVE_X11
static GOptionEntry notebook_options[] = {
{ "notebook", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &notebook_mode,
N_("Display notebook dialog"), NULL },
Expand All @@ -536,6 +539,7 @@ static GOptionEntry notebook_options[] = {
N_("Use stack mode"), NULL },
{ NULL }
};
#endif

#ifdef HAVE_TRAY
static GOptionEntry notification_options[] = {
Expand All @@ -553,6 +557,7 @@ static GOptionEntry notification_options[] = {
};
#endif

#ifdef HAVE_X11
static GOptionEntry paned_options[] = {
{ "paned", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &paned_mode,
N_("Display paned dialog"), NULL },
Expand All @@ -564,6 +569,7 @@ static GOptionEntry paned_options[] = {
N_("Set focused pane (1 or 2)"), N_("PANE") },
{ NULL }
};
#endif

static GOptionEntry picture_options[] = {
{ "picture", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &picture_mode,
Expand Down Expand Up @@ -1128,6 +1134,7 @@ set_justify (const gchar * option_name, const gchar * value, gpointer data, GErr
return TRUE;
}

#ifdef HAVE_X11
static gboolean
set_tab_pos (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
Expand All @@ -1144,6 +1151,7 @@ set_tab_pos (const gchar * option_name, const gchar * value, gpointer data, GErr

return TRUE;
}
#endif

static gboolean
set_expander (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
Expand Down Expand Up @@ -1182,6 +1190,7 @@ set_ellipsize (const gchar * option_name, const gchar * value, gpointer data, GE
return TRUE;
}

#ifdef HAVE_X11
static gboolean
set_orient (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
Expand All @@ -1194,6 +1203,7 @@ set_orient (const gchar * option_name, const gchar * value, gpointer data, GErro

return TRUE;
}
#endif

static gboolean
set_print_type (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
Expand Down Expand Up @@ -1534,14 +1544,16 @@ yad_set_mode (void)
options.mode = YAD_MODE_ICONS;
else if (list_mode)
options.mode = YAD_MODE_LIST;
#ifdef HAVE_X11
else if (notebook_mode)
options.mode = YAD_MODE_NOTEBOOK;
else if (paned_mode)
options.mode = YAD_MODE_PANED;
#endif
#ifdef HAVE_TRAY
else if (notification_mode)
options.mode = YAD_MODE_NOTIFICATION;
#endif
else if (paned_mode)
options.mode = YAD_MODE_PANED;
else if (picture_mode)
options.mode = YAD_MODE_PICTURE;
else if (print_mode)
Expand Down Expand Up @@ -1821,13 +1833,15 @@ yad_options_init (void)
options.list_data.col_align = NULL;
options.list_data.hdr_align = NULL;

#ifdef HAVE_X11
/* Initialize notebook data */
options.notebook_data.tabs = NULL;
options.notebook_data.borders = 5;
options.notebook_data.pos = GTK_POS_TOP;
options.notebook_data.active = 1;
options.notebook_data.expand = FALSE;
options.notebook_data.stack = FALSE;
#endif

#ifdef HAVE_TRAY
/* Initialize notification data */
Expand All @@ -1836,10 +1850,12 @@ yad_options_init (void)
options.notification_data.menu = NULL;
#endif

#ifdef HAVE_X11
/* Initialize paned data */
options.paned_data.orient = GTK_ORIENTATION_VERTICAL;
options.paned_data.splitter = -1;
options.paned_data.focused = 1;
#endif

/* Initialize picture data */
options.picture_data.size = YAD_PICTURE_ORIG;
Expand Down Expand Up @@ -2029,11 +2045,13 @@ yad_create_context (void)
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
g_option_context_add_group (tmp_ctx, a_group);

#ifdef HAVE_X11
/* Adds notebook option entries */
a_group = g_option_group_new ("notebook", _("Notebook options"), _("Show notebook dialog options"), NULL, NULL);
g_option_group_add_entries (a_group, notebook_options);
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
g_option_context_add_group (tmp_ctx, a_group);
#endif

#ifdef HAVE_TRAY
/* Adds notification option entries */
Expand All @@ -2044,11 +2062,13 @@ yad_create_context (void)
g_option_context_add_group (tmp_ctx, a_group);
#endif

#ifdef HAVE_X11
/* Adds paned option entries */
a_group = g_option_group_new ("paned", _("Paned dialog options"), _("Show paned dialog options"), NULL, NULL);
g_option_group_add_entries (a_group, paned_options);
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
g_option_context_add_group (tmp_ctx, a_group);
#endif

/* Adds picture option entries */
a_group = g_option_group_new ("picture", _("Picture dialog options"), _("Show picture dialog options"), NULL, NULL);
Expand Down
4 changes: 4 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,15 @@ get_tabs (key_t key, gboolean create)
for (i = 1; i < max_tab; i++)
{
t[i].pid = -1;
#ifdef HAVE_X11
t[i].xid = 0;
#endif
}
t[0].pid = shmid;
/* lastly, allow plugs to write shmem */
#ifdef HAVE_X11
t[0].xid = 1;
#endif
}

return t;
Expand Down
8 changes: 7 additions & 1 deletion src/yad.h
BEC1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <sys/ipc.h>
#include <fcntl.h>

#ifdef HAVE_X11
#include <gdk/gdkx.h>
#endif

#include <gtk/gtk.h>
#include <gtk/gtkx.h>
Expand Down Expand Up @@ -82,11 +84,13 @@ typedef enum {
#endif
YAD_MODE_ICONS,
YAD_MODE_LIST,
#ifdef HAVE_X11
YAD_MODE_NOTEBOOK,
YAD_MODE_PANED,
#endif
#ifdef HAVE_TRAY
YAD_MODE_NOTIFICATION,
#endif
YAD_MODE_PANED,
YAD_MODE_PICTURE,
YAD_MODE_PRINT,
YAD_MODE_PROGRESS,
Expand Down Expand Up @@ -629,7 +633,9 @@ extern gboolean ignore_esc;
/* TABS */
typedef struct {
pid_t pid;
#ifdef HAVE_X11
Window xid;
#endif
} YadNTabs;

/* pointer to shared memory for tabbed dialog */
Expand Down
0