summaryrefslogtreecommitdiff
path: root/capplets/accessibility/at-properties
diff options
context:
space:
mode:
authorWu Xiaotian <[email protected]>2019-06-27 22:27:07 +0800
committerraveit65 <[email protected]>2019-07-17 09:38:54 +0200
commitd361f977a857e769392cb210c629405ced6c99ba (patch)
tree016864b3d3a26906488a2b5f9f2af836e92bb074 /capplets/accessibility/at-properties
parent726e201050edd5bf3b46b12639bc490a9cefc465 (diff)
downloadmate-control-center-d361f977a857e769392cb210c629405ced6c99ba.tar.bz2
mate-control-center-d361f977a857e769392cb210c629405ced6c99ba.tar.xz
use current running DM preferences program
Diffstat (limited to 'capplets/accessibility/at-properties')
-rw-r--r--capplets/accessibility/at-properties/Makefile.am2
-rw-r--r--capplets/accessibility/at-properties/dm-util.c158
-rw-r--r--capplets/accessibility/at-properties/dm-util.h38
-rw-r--r--capplets/accessibility/at-properties/main.c36
4 files changed, 222 insertions, 12 deletions
diff --git a/capplets/accessibility/at-properties/Makefile.am b/capplets/accessibility/at-properties/Makefile.am
index c1c06848..370d459e 100644
--- a/capplets/accessibility/at-properties/Makefile.am
+++ b/capplets/accessibility/at-properties/Makefile.am
@@ -8,6 +8,8 @@ BUILT_SOURCES = \
nodist_mate_at_properties_SOURCES= $(BUILT_SOURCES)
mate_at_properties_LDADD = $(AT_CAPPLET_LIBS) $(MATECC_CAPPLETS_LIBS) $(top_builddir)/capplets/common/libcommon.la
mate_at_properties_SOURCES = \
+ dm-util.h \
+ dm-util.c \
main.c
mate_at_properties_LDFLAGS = -export-dynamic
diff --git a/capplets/accessibility/at-properties/dm-util.c b/capplets/accessibility/at-properties/dm-util.c
new file mode 100644
index 00000000..79c5e6e5
--- /dev/null
+++ b/capplets/accessibility/at-properties/dm-util.c
@@ -0,0 +1,158 @@
+/* vi: set sw=4 ts=4 wrap ai: */
+/*
+ * dm-util.c: This file is part of mate-control-center.
+ *
+ * Copyright (C) 2019 Wu Xiaotian <[email protected]>
+ *
+ * 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 2 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 <gio/gio.h>
+#include "dm-util.h"
+
+static GDBusProxy *get_sys_proxy (void)
+{
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ NULL,
+ &error);
+ if (proxy == NULL) {
+ g_warning ("Couldn't connect to system bus: %s", error->message);
+ g_error_free (error);
+ }
+ return proxy;
+}
+
+static gboolean dm_is_running (void)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+ gboolean running = FALSE;
+
+ proxy = get_sys_proxy ();
+ if (proxy == NULL)
+ return FALSE;
+
+ ret = g_dbus_proxy_call_sync (proxy,
+ "NameHasOwner",
+ g_variant_new ("(s)", "org.freedesktop.DisplayManager"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (ret == NULL) {
+ g_warning ("Couldn't call dbus method: %s", error->message);
+ g_error_free (error);
+ } else {
+ g_variant_get (ret, "(b)", &running);
+ g_variant_unref (ret);
+ }
+
+ if (proxy)
+ g_object_unref (proxy);
+
+ return running;
+}
+
+static gint
+dm_get_pid (GError **err)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+ guint32 pid = 0;
+
+ proxy = get_sys_proxy ();
+ if (proxy == NULL)
+ return FALSE;
+
+ ret = g_dbus_proxy_call_sync (proxy,
+ "GetConnectionUnixProcessID",
+ g_variant_new ("(s)", "org.freedesktop.DisplayManager"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (ret == NULL) {
+ g_propagate_error (err, error);
+ } else {
+ g_variant_get (ret, "(u)", &pid);
+ g_variant_unref (ret);
+ }
+
+ if (proxy)
+ g_object_unref (proxy);
+
+ return pid;
+}
+
+static gchar* get_cmdline_from_pid (gint pid)
+{
+ gchar path[255];
+ gchar *text = NULL;
+ gchar *cmdline = NULL;
+ GError *error = NULL;
+
+ g_snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
+ if (!g_file_get_contents (path, &text, NULL, &error)) {
+ g_warning ("get cmdline error: %s\n", error->message);
+ g_error_free (error);
+ return NULL;
+ } else {
+ cmdline = g_path_get_basename (text);
+ g_free (text);
+ }
+ return cmdline;
+}
+
+DMType dm_get_type(void)
+{
+ gint pid;
+ gchar *cmdline;
+
+ DMType dmtype = DM_TYPE_UNKNOWN;
+
+ if (!dm_is_running()) {
+ goto ret;
+ }
+
+ pid = dm_get_pid (NULL);
+ if (pid <= 1) {
+ goto ret;
+ }
+
+ cmdline = get_cmdline_from_pid (pid);
+ if (cmdline == NULL) {
+ goto ret;
+ }
+
+ if (g_strcmp0(cmdline, "lightdm") == 0) {
+ dmtype = DM_TYPE_LIGHTDM;
+ } else if (g_strcmp0(cmdline, "mdm") == 0) {
+ dmtype = DM_TYPE_MDM;
+ } else if (g_strcmp0(cmdline, "gdm") == 0) {
+ dmtype = DM_TYPE_GDM;
+ }
+ g_free (cmdline);
+ret:
+ return dmtype;
+}
diff --git a/capplets/accessibility/at-properties/dm-util.h b/capplets/accessibility/at-properties/dm-util.h
new file mode 100644
index 00000000..3b80b308
--- /dev/null
+++ b/capplets/accessibility/at-properties/dm-util.h
@@ -0,0 +1,38 @@
+/* vi: set sw=4 ts=4 wrap ai: */
+/*
+ * dm-util.h: This file is part of mate-control-center.
+ *
+ * Copyright (C) 2019 Wu Xiaotian <[email protected]>
+ *
+ * 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 2 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 __DM_UTIL_H__
+#define __DM_UTIL_H__ 1
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+ DM_TYPE_UNKNOWN,
+ DM_TYPE_LIGHTDM,
+ DM_TYPE_GDM,
+ DM_TYPE_MDM,
+} DMType;
+
+DMType dm_get_type(void);
+
+G_END_DECLS
+
+#endif /* __DM_UTIL_H__ */
diff --git a/capplets/accessibility/at-properties/main.c b/capplets/accessibility/at-properties/main.c
index 11e91bd3..44e07563 100644
--- a/capplets/accessibility/at-properties/main.c
+++ b/capplets/accessibility/at-properties/main.c
@@ -1,6 +1,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
+#include "dm-util.h"
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
@@ -33,7 +34,8 @@ create_builder (void)
if (gtk_builder_add_from_resource (builder, "/org/mate/mcc/accessibility/at/at-enable-dialog.ui", &error)) {
GObject *object;
- gchar *prog;
+ gchar *prog = NULL;
+ DMType dm_type;
object = gtk_builder_get_object (builder, "at_enable_image");
gtk_image_set_from_file (GTK_IMAGE (object),
@@ -44,15 +46,18 @@ create_builder (void)
gtk_image_set_from_file (GTK_IMAGE (object),
PIXMAPDIR "/at-support.png");
- prog = g_find_program_in_path ("lightdm-gtk-greeter-settings-pkexec");
- if (prog == NULL) {
+ dm_type = dm_get_type();
+ if (dm_type == DM_TYPE_MDM) {
prog = g_find_program_in_path ("mdmsetup");
- if (prog == NULL) {
- object = gtk_builder_get_object (builder, "login_button");
- gtk_widget_hide (GTK_WIDGET (object));
- }
+ } else if (dm_type == DM_TYPE_LIGHTDM) {
+ prog = g_find_program_in_path ("lightdm-gtk-greeter-settings-pkexec");
+ }
+ if (prog == NULL) {
+ object = gtk_builder_get_object (builder, "login_button");
+ gtk_widget_hide (GTK_WIDGET (object));
}
g_free (prog);
+
} else {
g_warning ("Could not load UI: %s", error->message);
g_error_free (error);
@@ -84,13 +89,20 @@ cb_mouse_preferences (GtkDialog *dialog, gint response_id)
static void
cb_login_preferences (GtkDialog *dialog, gint response_id)
{
- gchar *prog;
- prog = g_find_program_in_path ("lightdm-gtk-greeter-settings-pkexec");
- if (prog == NULL) {
+ DMType dm_type;
+ gchar *prog = NULL;
+
+ dm_type = dm_get_type();
+ if (dm_type == DM_TYPE_MDM) {
prog = g_find_program_in_path ("mdmsetup");
+ } else if (dm_type == DM_TYPE_LIGHTDM) {
+ prog = g_find_program_in_path ("lightdm-gtk-greeter-settings-pkexec");
+ }
+
+ if (prog != NULL) {
+ g_spawn_command_line_async (prog, NULL);
+ g_free(prog);
}
- g_spawn_command_line_async (prog, NULL);
- g_free(prog);
}
/* get_session_bus(), get_sm_proxy(), and do_logout() are all