2017-06-21 02:23:44 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2015-2017 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 "backends/meta-remote-desktop.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-cursor-renderer.h"
|
|
|
|
#include "backends/meta-remote-desktop-session.h"
|
|
|
|
#include "backends/native/meta-cursor-renderer-native.h"
|
|
|
|
#include "meta/meta-backend.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "meta-dbus-remote-desktop.h"
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
#define META_REMOTE_DESKTOP_DBUS_SERVICE "org.gnome.Mutter.RemoteDesktop"
|
|
|
|
#define META_REMOTE_DESKTOP_DBUS_PATH "/org/gnome/Mutter/RemoteDesktop"
|
2018-01-29 01:52:06 -05:00
|
|
|
#define META_REMOTE_DESKTOP_API_VERSION 1
|
2017-06-21 02:23:44 -04:00
|
|
|
|
2018-01-29 01:51:01 -05:00
|
|
|
typedef enum _MetaRemoteDesktopDeviceTypes
|
|
|
|
{
|
|
|
|
META_REMOTE_DESKTOP_DEVICE_TYPE_NONE = 0,
|
|
|
|
META_REMOTE_DESKTOP_DEVICE_TYPE_KEYBOARD = 1 << 0,
|
|
|
|
META_REMOTE_DESKTOP_DEVICE_TYPE_POINTER = 1 << 1,
|
|
|
|
META_REMOTE_DESKTOP_DEVICE_TYPE_TOUCHSCREEN = 1 << 2,
|
|
|
|
} MetaRemoteDesktopDeviceTypes;
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
struct _MetaRemoteDesktop
|
|
|
|
{
|
|
|
|
MetaDBusRemoteDesktopSkeleton parent;
|
|
|
|
|
2021-02-23 02:59:43 -05:00
|
|
|
MetaBackend *backend;
|
2017-06-21 02:23:44 -04:00
|
|
|
int dbus_name_id;
|
|
|
|
|
2020-04-21 09:44:32 -04:00
|
|
|
int inhibit_count;
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
GHashTable *sessions;
|
|
|
|
|
|
|
|
MetaDbusSessionWatcher *session_watcher;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_remote_desktop_init_iface (MetaDBusRemoteDesktopIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MetaRemoteDesktop,
|
|
|
|
meta_remote_desktop,
|
|
|
|
META_DBUS_TYPE_REMOTE_DESKTOP_SKELETON,
|
|
|
|
G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_REMOTE_DESKTOP,
|
|
|
|
meta_remote_desktop_init_iface));
|
|
|
|
|
2020-04-21 09:44:32 -04:00
|
|
|
void
|
|
|
|
meta_remote_desktop_inhibit (MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
remote_desktop->inhibit_count++;
|
|
|
|
if (remote_desktop->inhibit_count == 1)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, remote_desktop->sessions);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
MetaRemoteDesktopSession *session = value;
|
|
|
|
|
|
|
|
g_hash_table_iter_steal (&iter);
|
|
|
|
meta_remote_desktop_session_close (session);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_remote_desktop_uninhibit (MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
g_return_if_fail (remote_desktop->inhibit_count > 0);
|
|
|
|
|
|
|
|
remote_desktop->inhibit_count--;
|
|
|
|
}
|
|
|
|
|
2021-02-23 02:59:43 -05:00
|
|
|
MetaBackend *
|
|
|
|
meta_remote_desktop_get_backend (MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
return remote_desktop->backend;
|
|
|
|
}
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
GDBusConnection *
|
|
|
|
meta_remote_desktop_get_connection (MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
GDBusInterfaceSkeleton *interface_skeleton =
|
|
|
|
G_DBUS_INTERFACE_SKELETON (remote_desktop);
|
|
|
|
|
|
|
|
return g_dbus_interface_skeleton_get_connection (interface_skeleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaRemoteDesktopSession *
|
|
|
|
meta_remote_desktop_get_session (MetaRemoteDesktop *remote_desktop,
|
|
|
|
const char *session_id)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (remote_desktop->sessions, session_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_session_closed (MetaRemoteDesktopSession *session,
|
|
|
|
MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
char *session_id;
|
|
|
|
|
|
|
|
session_id = meta_remote_desktop_session_get_session_id (session);
|
|
|
|
g_hash_table_remove (remote_desktop->sessions, session_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_create_session (MetaDBusRemoteDesktop *skeleton,
|
|
|
|
GDBusMethodInvocation *invocation)
|
|
|
|
{
|
|
|
|
MetaRemoteDesktop *remote_desktop = META_REMOTE_DESKTOP (skeleton);
|
2017-08-25 03:19:53 -04:00
|
|
|
const char *peer_name;
|
2017-06-21 02:23:44 -04:00
|
|
|
MetaRemoteDesktopSession *session;
|
|
|
|
GError *error = NULL;
|
|
|
|
char *session_id;
|
|
|
|
char *session_path;
|
|
|
|
const char *client_dbus_name;
|
|
|
|
|
2020-04-21 09:44:32 -04:00
|
|
|
if (remote_desktop->inhibit_count > 0)
|
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
|
|
|
|
G_DBUS_ERROR_ACCESS_DENIED,
|
|
|
|
"Session creation inhibited");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-25 03:19:53 -04:00
|
|
|
peer_name = g_dbus_method_invocation_get_sender (invocation);
|
2017-06-21 02:23:44 -04:00
|
|
|
session = meta_remote_desktop_session_new (remote_desktop,
|
2017-08-25 03:19:53 -04:00
|
|
|
peer_name,
|
2017-06-21 02:23:44 -04:00
|
|
|
&error);
|
|
|
|
if (!session)
|
|
|
|
{
|
|
|
|
g_warning ("Failed to create remote desktop session: %s",
|
|
|
|
error->message);
|
|
|
|
|
|
|
|
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
|
|
|
|
G_DBUS_ERROR_FAILED,
|
|
|
|
"Failed to create session: %s",
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
session_id = meta_remote_desktop_session_get_session_id (session);
|
|
|
|
g_hash_table_insert (remote_desktop->sessions,
|
|
|
|
session_id,
|
|
|
|
session);
|
|
|
|
|
|
|
|
client_dbus_name = g_dbus_method_invocation_get_sender (invocation);
|
|
|
|
meta_dbus_session_watcher_watch_session (remote_desktop->session_watcher,
|
|
|
|
client_dbus_name,
|
|
|
|
META_DBUS_SESSION (session));
|
|
|
|
|
|
|
|
session_path = meta_remote_desktop_session_get_object_path (session);
|
|
|
|
meta_dbus_remote_desktop_complete_create_session (skeleton,
|
|
|
|
invocation,
|
|
|
|
session_path);
|
|
|
|
|
|
|
|
g_signal_connect (session, "session-closed",
|
|
|
|
G_CALLBACK (on_session_closed),
|
|
|
|
remote_desktop);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_remote_desktop_init_iface (MetaDBusRemoteDesktopIface *iface)
|
|
|
|
{
|
|
|
|
iface->handle_create_session = handle_create_session;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_bus_acquired (GDBusConnection *connection,
|
|
|
|
const char *name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaRemoteDesktop *remote_desktop = user_data;
|
|
|
|
GDBusInterfaceSkeleton *interface_skeleton =
|
|
|
|
G_DBUS_INTERFACE_SKELETON (remote_desktop);
|
2023-01-27 09:34:38 -05:00
|
|
|
g_autoptr (GError) error = NULL;
|
2017-06-21 02:23:44 -04:00
|
|
|
|
|
|
|
if (!g_dbus_interface_skeleton_export (interface_skeleton,
|
|
|
|
connection,
|
|
|
|
META_REMOTE_DESKTOP_DBUS_PATH,
|
|
|
|
&error))
|
2020-10-02 11:54:56 -04:00
|
|
|
g_warning ("Failed to export remote desktop object: %s", error->message);
|
2017-06-21 02:23:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_name_acquired (GDBusConnection *connection,
|
|
|
|
const char *name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-10-02 11:54:56 -04:00
|
|
|
g_info ("Acquired name %s", name);
|
2017-06-21 02:23:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_name_lost (GDBusConnection *connection,
|
|
|
|
const char *name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-10-02 11:54:56 -04:00
|
|
|
g_warning ("Lost or failed to acquire name %s", name);
|
2017-06-21 02:23:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_remote_desktop_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
MetaRemoteDesktop *remote_desktop = META_REMOTE_DESKTOP (object);
|
|
|
|
|
|
|
|
remote_desktop->dbus_name_id =
|
|
|
|
g_bus_own_name (G_BUS_TYPE_SESSION,
|
|
|
|
META_REMOTE_DESKTOP_DBUS_SERVICE,
|
|
|
|
G_BUS_NAME_OWNER_FLAGS_NONE,
|
|
|
|
on_bus_acquired,
|
|
|
|
on_name_acquired,
|
|
|
|
on_name_lost,
|
|
|
|
remote_desktop,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2021-05-05 08:22:18 -04:00
|
|
|
static void
|
|
|
|
on_prepare_shutdown (MetaBackend *backend,
|
|
|
|
MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, remote_desktop->sessions);
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &value))
|
|
|
|
{
|
|
|
|
MetaRemoteDesktopSession *session = value;
|
|
|
|
|
|
|
|
g_hash_table_iter_steal (&iter);
|
|
|
|
meta_remote_desktop_session_close (session);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
static void
|
|
|
|
meta_remote_desktop_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaRemoteDesktop *remote_desktop = META_REMOTE_DESKTOP (object);
|
|
|
|
|
|
|
|
if (remote_desktop->dbus_name_id != 0)
|
|
|
|
g_bus_unown_name (remote_desktop->dbus_name_id);
|
|
|
|
|
2021-05-05 08:22:18 -04:00
|
|
|
g_assert (g_hash_table_size (remote_desktop->sessions) == 0);
|
2017-06-21 02:23:44 -04:00
|
|
|
g_hash_table_destroy (remote_desktop->sessions);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_remote_desktop_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaRemoteDesktop *
|
2021-02-23 02:59:43 -05:00
|
|
|
meta_remote_desktop_new (MetaBackend *backend,
|
|
|
|
MetaDbusSessionWatcher *session_watcher)
|
2017-06-21 02:23:44 -04:00
|
|
|
{
|
|
|
|
MetaRemoteDesktop *remote_desktop;
|
|
|
|
|
|
|
|
remote_desktop = g_object_new (META_TYPE_REMOTE_DESKTOP, NULL);
|
2021-02-23 02:59:43 -05:00
|
|
|
remote_desktop->backend = backend;
|
2017-06-21 02:23:44 -04:00
|
|
|
remote_desktop->session_watcher = session_watcher;
|
|
|
|
|
2021-05-05 08:22:18 -04:00
|
|
|
g_signal_connect (backend, "prepare-shutdown",
|
|
|
|
G_CALLBACK (on_prepare_shutdown),
|
|
|
|
remote_desktop);
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
return remote_desktop;
|
|
|
|
}
|
|
|
|
|
2018-01-29 01:51:01 -05:00
|
|
|
static MetaRemoteDesktopDeviceTypes
|
|
|
|
calculate_supported_device_types (void)
|
|
|
|
{
|
2019-10-02 08:40:40 -04:00
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
ClutterSeat *seat = clutter_backend_get_default_seat (backend);
|
2018-01-29 01:51:01 -05:00
|
|
|
ClutterVirtualDeviceType device_types;
|
|
|
|
MetaRemoteDesktopDeviceTypes supported_devices =
|
|
|
|
META_REMOTE_DESKTOP_DEVICE_TYPE_NONE;
|
|
|
|
|
|
|
|
device_types =
|
2019-10-02 08:40:40 -04:00
|
|
|
clutter_seat_get_supported_virtual_device_types (seat);
|
2018-01-29 01:51:01 -05:00
|
|
|
|
|
|
|
if (device_types & CLUTTER_VIRTUAL_DEVICE_TYPE_KEYBOARD)
|
|
|
|
supported_devices |= META_REMOTE_DESKTOP_DEVICE_TYPE_KEYBOARD;
|
|
|
|
if (device_types & CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER)
|
|
|
|
supported_devices |= META_REMOTE_DESKTOP_DEVICE_TYPE_POINTER;
|
|
|
|
if (device_types & CLUTTER_VIRTUAL_DEVICE_TYPE_TOUCHSCREEN)
|
|
|
|
supported_devices |= META_REMOTE_DESKTOP_DEVICE_TYPE_TOUCHSCREEN;
|
|
|
|
|
|
|
|
return supported_devices;
|
|
|
|
}
|
|
|
|
|
2017-06-21 02:23:44 -04:00
|
|
|
static void
|
|
|
|
meta_remote_desktop_init (MetaRemoteDesktop *remote_desktop)
|
|
|
|
{
|
|
|
|
remote_desktop->sessions = g_hash_table_new (g_str_hash, g_str_equal);
|
2018-01-29 01:51:01 -05:00
|
|
|
|
|
|
|
meta_dbus_remote_desktop_set_supported_device_types (
|
|
|
|
META_DBUS_REMOTE_DESKTOP (remote_desktop),
|
|
|
|
calculate_supported_device_types ());
|
2018-01-29 01:52:06 -05:00
|
|
|
meta_dbus_remote_desktop_set_version (
|
|
|
|
META_DBUS_REMOTE_DESKTOP (remote_desktop),
|
|
|
|
META_REMOTE_DESKTOP_API_VERSION);
|
2017-06-21 02:23:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_remote_desktop_class_init (MetaRemoteDesktopClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructed = meta_remote_desktop_constructed;
|
|
|
|
object_class->finalize = meta_remote_desktop_finalize;
|
|
|
|
}
|