Call out to the session helper and get the monitor dir

tingping/wmclass
Alexander Larsson 2015-01-27 21:33:51 +00:00
parent fca4a16209
commit 3a56d3f465
3 changed files with 42 additions and 1 deletions

View File

@ -89,6 +89,7 @@ xdg_app_SOURCES = \
xdg-app-dir.h \
xdg-app-utils.h \
xdg-app-utils.c \
$(dbus_built_sources) \
$(NULL)
xdg_app_LDADD = $(BASE_LIBS) $(OSTREE_LIBS) $(SOUP_LIBS)

View File

@ -10,6 +10,7 @@
#include "xdg-app-builtins.h"
#include "xdg-app-utils.h"
#include "xdg-app-dbus.h"
static char *opt_arch;
static char *opt_branch;
@ -236,6 +237,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
gs_unref_object GFile *runtime_files = NULL;
gs_unref_object GFile *metadata = NULL;
gs_unref_object GFile *runtime_metadata = NULL;
gs_unref_object XdgAppSessionHelper *session_helper = NULL;
gs_free char *metadata_contents = NULL;
gs_free char *runtime_metadata_contents = NULL;
gs_free char *runtime = NULL;
@ -248,6 +250,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
gs_free_error GError *my_error = NULL;
gs_free_error GError *my_error2 = NULL;
gs_unref_ptrarray GPtrArray *argv_array = NULL;
gs_free char *monitor_path = NULL;
gsize metadata_size, runtime_metadata_size;
const char *app;
const char *branch = "master";
@ -372,6 +375,22 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
else
command = default_command;
session_helper = xdg_app_session_helper_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
"org.freedesktop.XdgApp.SessionHelper",
"/org/freedesktop/XdgApp/SessionHelper",
NULL, NULL);
if (session_helper)
{
if (xdg_app_session_helper_call_request_monitor_sync (session_helper,
&monitor_path,
NULL, NULL))
{
g_ptr_array_add (argv_array, g_strdup ("-m"));
g_ptr_array_add (argv_array, monitor_path);
}
}
if (g_key_file_get_boolean (metakey, "Environment", "ipc", NULL))
g_ptr_array_add (argv_array, g_strdup ("-i"));

View File

@ -185,7 +185,7 @@ strdup_printf (const char *format,
void
usage (char **argv)
{
fprintf (stderr, "usage: %s [-n] [-i] [-p <pulsaudio socket>] [-x X11 socket] [-y Wayland socket] [-w] [-W] [-a <path to app>] [-v <path to var>] [-b <target-dir>=<src-dir>] <path to runtime> <command..>\n", argv[0]);
fprintf (stderr, "usage: %s [-n] [-i] [-p <pulsaudio socket>] [-x X11 socket] [-y Wayland socket] [-w] [-W] [-m <path to monitor dir>] [-a <path to app>] [-v <path to var>] [-b <target-dir>=<src-dir>] <path to runtime> <command..>\n", argv[0]);
exit (1);
}
@ -252,6 +252,7 @@ static const create_table_t create[] = {
{ FILE_TYPE_DIR, "run/user", 0755},
{ FILE_TYPE_DIR, "run/user/%1$d", 0700, NULL, FILE_FLAGS_USER_OWNED },
{ FILE_TYPE_DIR, "run/user/%1$d/pulse", 0700, NULL, FILE_FLAGS_USER_OWNED },
{ FILE_TYPE_DIR, "run/user/%1$d/xdg-app-monitor", 0700, NULL, FILE_FLAGS_USER_OWNED },
{ FILE_TYPE_REGULAR, "run/user/%1$d/pulse/native", 0700, NULL, FILE_FLAGS_USER_OWNED },
{ FILE_TYPE_DIR, "var", 0755},
{ FILE_TYPE_SYMLINK, "var/tmp", 0755, "/tmp"},
@ -886,6 +887,7 @@ main (int argc,
int system_mode = 0;
char *runtime_path = NULL;
char *app_path = NULL;
char *monitor_path = NULL;
char *var_path = NULL;
char *extra_dirs_src[MAX_EXTRA_DIRS];
char *extra_dirs_dest[MAX_EXTRA_DIRS];
@ -985,6 +987,15 @@ main (int argc,
n_args -= 2;
break;
case 'm':
if (n_args < 2)
usage (argv);
monitor_path = args[1];
args += 2;
n_args -= 2;
break;
case 'b':
if (n_args < 2)
usage (argv);
@ -1213,6 +1224,16 @@ main (int argc,
link_extra_etc_dirs ();
if (monitor_path)
{
char *monitor_mount_path = strdup_printf ("run/user/%d/xdg-app-monitor", getuid());
if (bind_mount (monitor_path, monitor_mount_path, BIND_READONLY))
die ("can't bind monitor dir");
free (monitor_mount_path);
}
/* Bind mount in X socket
* This is a bit iffy, as Xlib typically uses abstract unix domain sockets
* to connect to X, but that is not namespaced. We instead set DISPLAY=99