[mutter/wip/login1] login1



commit dfad7709e62686833835dd73a349af9e8b3b5722
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Dec 31 17:44:45 2013 -0500

    login1

 .gitignore                         |    1 +
 src/Makefile.am                    |   25 +-
 src/org.freedesktop.login1.xml     |   70 ++++
 src/wayland/meta-login1.c          |  180 +++++++++
 src/wayland/meta-login1.h          |   30 ++
 src/wayland/meta-wayland-private.h |    4 +-
 src/wayland/meta-wayland.c         |   37 +--
 src/wayland/meta-weston-launch.c   |  387 -------------------
 src/wayland/meta-weston-launch.h   |   42 --
 src/wayland/weston-launch.c        |  751 ------------------------------------
 src/wayland/weston-launch.h        |   68 ----
 11 files changed, 301 insertions(+), 1294 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ae4d6b0..6f35894 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,6 +77,7 @@ src/mutter-marshal.[ch]
 src/stamp-mutter-marshal.h
 src/meta-dbus-xrandr.[ch]
 src/meta-dbus-idle-monitor.[ch]
+src/meta-dbus-login1.[ch]
 src/mutter-plugins.pc
 src/wayland/gtk-shell-protocol.c
 src/wayland/gtk-shell-client-protocol.h
diff --git a/src/Makefile.am b/src/Makefile.am
index b81c6ec..f936890 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,6 +38,7 @@ INCLUDES += \
 mutter_built_sources = \
        $(dbus_idle_built_sources)              \
        $(dbus_xrandr_built_sources)            \
+       $(dbus_login1_built_sources)            \
        mutter-enum-types.h                     \
        mutter-enum-types.c                     \
        wayland/gtk-shell-protocol.c            \
@@ -213,8 +214,8 @@ libmutter_wayland_la_SOURCES +=                     \
        wayland/meta-wayland-surface.h          \
        wayland/meta-wayland-types.h            \
        wayland/meta-wayland-versions.h         \
-       wayland/meta-weston-launch.c            \
-       wayland/meta-weston-launch.h
+       wayland/meta-login1.c                   \
+       wayland/meta-login1.h
 
 libmutter_wayland_la_LDFLAGS = -no-undefined
 libmutter_wayland_la_LIBADD  = $(MUTTER_LIBS)
@@ -266,17 +267,6 @@ bin_PROGRAMS=mutter-wayland
 mutter_wayland_SOURCES = core/mutter.c
 mutter_wayland_LDADD = $(MUTTER_LIBS) libmutter-wayland.la
 
-bin_PROGRAMS+=mutter-launch
-
-mutter_launch_SOURCES = wayland/weston-launch.c wayland/weston-launch.h
-
-mutter_launch_CFLAGS = $(MUTTER_LAUNCH_CFLAGS) -DLIBDIR=\"$(libdir)\"
-mutter_launch_LDFLAGS = $(MUTTER_LAUNCH_LIBS) -lpam
-
-install-exec-hook:
-       -chown root $(DESTDIR)$(bindir)/mutter-launch
-       -chmod u+s $(DESTDIR)$(bindir)/mutter-launch
-
 if HAVE_INTROSPECTION
 include $(INTROSPECTION_MAKEFILE)
 
@@ -412,6 +402,15 @@ $(dbus_idle_built_sources) : Makefile.am idle-monitor.xml
                --c-generate-object-manager                                             \
                $(srcdir)/idle-monitor.xml
 
+dbus_login1_built_sources = meta-dbus-login1.c meta-dbus-login1.h
+
+$(dbus_login1_built_sources) : Makefile.am org.freedesktop.login1.xml
+       $(AM_V_GEN)gdbus-codegen                                                        \
+               --interface-prefix org.freedesktop.login1                               \
+               --c-namespace Login1                                                    \
+               --generate-c-code meta-dbus-login1                                      \
+               $(srcdir)/org.freedesktop.login1.xml
+
 wayland/%-protocol.c : $(top_builddir)/protocol/%.xml
        mkdir -p wayland
        $(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@
diff --git a/src/org.freedesktop.login1.xml b/src/org.freedesktop.login1.xml
new file mode 100644
index 0000000..3516c5c
--- /dev/null
+++ b/src/org.freedesktop.login1.xml
@@ -0,0 +1,70 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd";>
+<node>
+  <interface name="org.freedesktop.login1.Session">
+    <method name="Terminate"/>
+    <method name="Activate"/>
+    <method name="Lock"/>
+    <method name="Unlock"/>
+    <method name="SetIdleHint">
+      <arg name="b" type="b"/>
+    </method>
+    <method name="Kill">
+      <arg name="who" type="s"/>
+      <arg name="signal" type="s"/>
+    </method>
+    <method name="TakeControl">
+      <arg name="force" type="b"/>
+    </method>
+    <method name="ReleaseControl"/>
+    <method name="TakeDevice">
+      <arg name="major" type="u" direction="in"/>
+      <arg name="minor" type="u" direction="in"/>
+      <arg name="fd" type="h" direction="out"/>
+      <arg name="paused" type="b" direction="out"/>
+    </method>
+    <method name="ReleaseDevice">
+      <arg name="major" type="u"/>
+      <arg name="minor" type="u"/>
+    </method>
+    <method name="PauseDeviceComplete">
+      <arg name="major" type="u"/>
+      <arg name="minor" type="u"/>
+    </method>
+    <signal name="PauseDevice">
+      <arg name="major" type="u"/>
+      <arg name="minor" type="u"/>
+      <arg name="type" type="s"/>
+    </signal>
+    <signal name="ResumeDevice">
+      <arg name="major" type="u"/>
+      <arg name="minor" type="u"/>
+      <arg name="fd" type="h"/>
+    </signal>
+    <signal name="Lock"/>
+    <signal name="Unlock"/>
+    <property name="Id" type="s" access="read"/>
+    <property name="User" type="(uo)" access="read"/>
+    <property name="Name" type="s" access="read"/>
+    <property name="Timestamp" type="t" access="read"/>
+    <property name="TimestampMonotonic" type="t" access="read"/>
+    <property name="VTNr" type="u" access="read"/>
+    <property name="Seat" type="(so)" access="read"/>
+    <property name="TTY" type="s" access="read"/>
+    <property name="Display" type="s" access="read"/>
+    <property name="Remote" type="b" access="read"/>
+    <property name="RemoteHost" type="s" access="read"/>
+    <property name="RemoteUser" type="s" access="read"/>
+    <property name="Service" type="s" access="read"/>
+    <property name="Scope" type="s" access="read"/>
+    <property name="Leader" type="u" access="read"/>
+    <property name="Audit" type="u" access="read"/>
+    <property name="Type" type="s" access="read"/>
+    <property name="Class" type="s" access="read"/>
+    <property name="Active" type="b" access="read"/>
+    <property name="State" type="s" access="read"/>
+    <property name="IdleHint" type="b" access="read"/>
+    <property name="IdleSinceHint" type="t" access="read"/>
+    <property name="IdleSinceHintMonotonic" type="t" access="read"/>
+  </interface>
+</node>
diff --git a/src/wayland/meta-login1.c b/src/wayland/meta-login1.c
new file mode 100644
index 0000000..29e866e
--- /dev/null
+++ b/src/wayland/meta-login1.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "meta-login1.h"
+
+#include "meta-dbus-login1.h"
+
+#include <clutter/clutter.h>
+#include <clutter/evdev/clutter-evdev.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+struct _MetaLogin1
+{
+  Login1Session *session_proxy;
+};
+
+static Login1Session *
+get_session_proxy (GCancellable *cancellable)
+{
+  return login1_session_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                                "org.freedesktop.login1",
+                                                "/org/freedesktop1/login1/session/self",
+                                                cancellable, NULL);
+}
+
+static void
+session_enter (void)
+{
+  ClutterBackend *backend;
+  CoglContext *cogl_context;
+  CoglDisplay *cogl_display;
+
+  backend = clutter_get_default_backend ();
+  cogl_context = clutter_backend_get_cogl_context (backend);
+  cogl_display = cogl_context_get_display (cogl_context);
+  cogl_kms_display_queue_modes_reset (cogl_display);
+
+  clutter_evdev_reclaim_devices ();
+}
+
+static void
+session_leave (void)
+{
+  clutter_evdev_release_devices ();
+}
+
+static void
+meta_login1_sync_active (MetaLogin1 *self)
+{
+  gboolean active = login1_session_get_active (LOGIN1_SESSION (self->session_proxy));
+
+  if (active)
+    session_enter ();
+  else
+    session_leave ();
+}
+
+static void
+on_active_changed (Login1Session *session,
+                   GParamSpec    *pspec,
+                   gpointer       user_data)
+{
+  MetaLogin1 *self = user_data;
+  meta_login1_sync_active (self);
+}
+
+static gboolean
+meta_login1_take_device (MetaLogin1    *self,
+                         int            dev_major,
+                         int            dev_minor,
+                         int           *out_fd,
+                         GCancellable  *cancellable,
+                         GError       **error)
+{
+  gboolean ret = FALSE;
+  GVariant *fd_variant = NULL;
+  int fd = -1;
+
+  if (!login1_session_call_take_device_sync (self->session_proxy,
+                                             dev_major,
+                                             dev_minor,
+                                             &fd_variant,
+                                             NULL, /* paused */
+                                             NULL,
+                                             error))
+    goto out;
+
+  fd = g_variant_get_handle (fd_variant);
+  *out_fd = fd;
+
+ out:
+  if (fd_variant)
+    g_variant_unref (fd_variant);
+  return ret;
+}
+
+static gboolean
+get_device_info (const char *path,
+                 int        *out_major,
+                 int        *out_minor)
+{
+  gboolean ret = FALSE;
+  int r;
+  struct stat st;
+
+  r = stat (path, &st);
+  if (r < 0)
+    goto out;
+  if (!S_ISCHR (st.st_mode))
+    goto out;
+
+  *out_major = major (st.st_rdev);
+  *out_minor = minor (st.st_rdev);
+  ret = TRUE;
+
+ out:
+  return ret;
+}
+
+static int
+on_evdev_device_open (const char  *path,
+                     int          flags,
+                     gpointer     user_data,
+                     GError     **error)
+{
+  MetaLogin1 *self = user_data;
+  int fd;
+  int major, minor;
+
+  if (!get_device_info (path, &major, &minor))
+    return -1;
+
+  if (!meta_login1_take_device (self, major, minor, &fd, NULL, NULL))
+    return -1;
+
+  return fd;
+}
+
+MetaLogin1 *
+meta_login1_new (void)
+{
+  MetaLogin1 *self = g_slice_new0 (MetaLogin1);
+
+  clutter_evdev_set_open_callback (on_evdev_device_open, self);
+  self->session_proxy = get_session_proxy (NULL);
+
+  g_signal_connect (self->session_proxy, "notify::active", G_CALLBACK (on_active_changed), self);
+  meta_login1_sync_active (self);
+
+  return self;
+}
+
+void
+meta_login1_free (MetaLogin1 *self)
+{
+  g_object_unref (self->session_proxy);
+  g_slice_free (MetaLogin1, self);
+}
diff --git a/src/wayland/meta-login1.h b/src/wayland/meta-login1.h
new file mode 100644
index 0000000..cecf338
--- /dev/null
+++ b/src/wayland/meta-login1.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_LOGIN1_H
+#define META_LOGIN1_H
+
+#include <glib-object.h>
+
+typedef struct _MetaLogin1 MetaLogin1;
+
+MetaLogin1 *meta_login1_new  (void);
+void        meta_login1_free (MetaLogin1 *self);
+
+#endif
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 26cd88e..33a3f0e 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -28,7 +28,7 @@
 #include <cairo.h>
 
 #include "window-private.h"
-#include "meta-weston-launch.h"
+#include "meta-login1.h"
 #include <meta/meta-cursor-tracker.h>
 
 #include "meta-wayland-types.h"
@@ -79,7 +79,7 @@ struct _MetaWaylandCompositor
   struct wl_client *xwayland_client;
   struct wl_resource *xserver_resource;
 
-  MetaLauncher *launcher;
+  MetaLogin1 *login1;
   gboolean native;
 
   MetaWaylandSeat *seat;
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 84b51ed..5b9bf59 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -52,7 +52,7 @@
 #include <meta/main.h>
 #include "frame.h"
 #include "meta-idle-monitor-private.h"
-#include "meta-weston-launch.h"
+#include "meta-login1.h"
 #include "monitor-private.h"
 
 static MetaWaylandCompositor _meta_wayland_compositor;
@@ -624,21 +624,13 @@ meta_wayland_log_func (const char *fmt,
 }
 
 static gboolean
-are_we_native (int *out_drm_fd)
+are_we_native (void)
 {
   ClutterBackend *backend = clutter_get_default_backend ();
   CoglContext *cogl_context = clutter_backend_get_cogl_context (backend);
   CoglRenderer *cogl_renderer = cogl_display_get_renderer (cogl_context_get_display (cogl_context));
 
-  if (cogl_renderer_get_winsys_id (cogl_renderer) == COGL_WINSYS_ID_EGL_KMS)
-    {
-      *out_drm_fd = cogl_kms_renderer_get_kms_fd (cogl_renderer);
-      return TRUE;
-    }
-  else
-    {
-      return FALSE;
-    }
+  return (cogl_renderer_get_winsys_id (cogl_renderer) == COGL_WINSYS_ID_EGL_KMS);
 }
 
 void
@@ -647,7 +639,6 @@ meta_wayland_init (void)
   MetaWaylandCompositor *compositor = &_meta_wayland_compositor;
   MetaMonitorManager *monitors;
   char *display_name;
-  int drm_fd;
 
   memset (compositor, 0, sizeof (MetaWaylandCompositor));
 
@@ -686,27 +677,11 @@ meta_wayland_init (void)
 
   clutter_wayland_set_compositor_display (compositor->wayland_display);
 
-  if (getenv ("WESTON_LAUNCHER_SOCK"))
-      compositor->launcher = meta_launcher_new ();
-
   if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
     g_error ("Failed to initialize Clutter");
 
-  if (are_we_native (&drm_fd))
-    {
-      GError *error = NULL;
-      if (!meta_launcher_set_drm_fd (compositor->launcher, drm_fd, &error))
-       {
-         g_error ("Failed to set DRM fd to weston-launch and become DRM master: %s", error->message);
-         g_error_free (error);
-       }
-
-      compositor->native = TRUE;
-    }
-  else
-    {
-      compositor->native = FALSE;
-    }
+  compositor->native = are_we_native ();
+  compositor->login1 = meta_login1_new ();
 
   meta_monitor_manager_initialize ();
   monitors = meta_monitor_manager_get ();
@@ -761,7 +736,7 @@ meta_wayland_finalize (void)
   compositor = meta_wayland_compositor_get_default ();
 
   meta_xwayland_stop (compositor);
-  meta_launcher_free (compositor->launcher);
+  meta_login1_free (compositor->login1);
 }
 
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]