[gnome-flashback] screensaver: add gf_find_systemd_session
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] screensaver: add gf_find_systemd_session
- Date: Tue, 10 Dec 2019 21:35:04 +0000 (UTC)
commit 6ec4ffce6b7ad61ba0533f9a5743cc13a46a05d1
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Dec 10 22:21:16 2019 +0200
screensaver: add gf_find_systemd_session
Will be needed by next commit, XDG_SESSION_ID is blacklisted by
gnome-session and will not be available:
https://gitlab.gnome.org/GNOME/gnome-session/commit/646b9bc0584d02
configure.ac | 1 +
gnome-flashback/libscreensaver/Makefile.am | 2 +
.../libscreensaver/gf-screensaver-utils.c | 74 ++++++++++++++++++++++
.../libscreensaver/gf-screensaver-utils.h | 29 +++++++++
4 files changed, 106 insertions(+)
---
diff --git a/configure.ac b/configure.ac
index 8acd621..0317836 100644
--- a/configure.ac
+++ b/configure.ac
@@ -231,6 +231,7 @@ PKG_CHECK_MODULES([SCREENSAVER], [
glib-2.0 >= $GLIB_REQUIRED
gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED
gtk+-3.0 >= $GTK_REQUIRED
+ libsystemd
])
PKG_CHECK_MODULES([SCREENSHOT], [
diff --git a/gnome-flashback/libscreensaver/Makefile.am b/gnome-flashback/libscreensaver/Makefile.am
index acdad6d..6b2f51a 100644
--- a/gnome-flashback/libscreensaver/Makefile.am
+++ b/gnome-flashback/libscreensaver/Makefile.am
@@ -28,6 +28,8 @@ libscreensaver_la_SOURCES = \
gf-prefs.h \
gf-screensaver.c \
gf-screensaver.h \
+ gf-screensaver-utils.c \
+ gf-screensaver-utils.h \
gf-watcher.c \
gf-watcher.h \
$(BUILT_SOURCES) \
diff --git a/gnome-flashback/libscreensaver/gf-screensaver-utils.c
b/gnome-flashback/libscreensaver/gf-screensaver-utils.c
new file mode 100644
index 0000000..1840496
--- /dev/null
+++ b/gnome-flashback/libscreensaver/gf-screensaver-utils.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "gf-screensaver-utils.h"
+
+#include <systemd/sd-login.h>
+#include <unistd.h>
+
+gboolean
+gf_find_systemd_session (char **session_id)
+{
+ int n_sessions;
+ char **sessions;
+ char *session;
+ int i;
+
+ n_sessions = sd_uid_get_sessions (getuid (), 0, &sessions);
+
+ if (n_sessions < 0)
+ {
+ g_debug ("Failed to get sessions for user %d", getuid ());
+ return FALSE;
+ }
+
+ session = NULL;
+
+ for (i = 0; i < n_sessions; i++)
+ {
+ int r;
+ char *type;
+
+ r = sd_session_get_type (sessions[i], &type);
+
+ if (r < 0)
+ {
+ g_debug ("Couldn't get type for session '%s': %s",
+ sessions[i], strerror (-r));
+ continue;
+ }
+
+ if (g_strcmp0 (type, "x11") != 0)
+ {
+ free (type);
+ continue;
+ }
+
+ session = sessions[i];
+ free (type);
+ }
+
+ if (session != NULL)
+ *session_id = g_strdup (session);
+
+ for (i = 0; i < n_sessions; i++)
+ free (sessions[i]);
+ free (sessions);
+
+ return session != NULL;
+}
diff --git a/gnome-flashback/libscreensaver/gf-screensaver-utils.h
b/gnome-flashback/libscreensaver/gf-screensaver-utils.h
new file mode 100644
index 0000000..6e0b2ea
--- /dev/null
+++ b/gnome-flashback/libscreensaver/gf-screensaver-utils.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GF_SCREENSAVER_UTILS_H
+#define GF_SCREENSAVER_UTILS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean gf_find_systemd_session (char **session_id);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]