mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
seat-impl: Open/close files via device pool
This replaces going through MetaLauncher to open/close restricted files. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1828>
This commit is contained in:
parent
f6f9c093ba
commit
7ce266628e
@ -147,6 +147,7 @@ meta_backend_native_create_default_seat (MetaBackend *backend,
|
|||||||
flags = META_SEAT_NATIVE_FLAG_NONE;
|
flags = META_SEAT_NATIVE_FLAG_NONE;
|
||||||
|
|
||||||
return CLUTTER_SEAT (g_object_new (META_TYPE_SEAT_NATIVE,
|
return CLUTTER_SEAT (g_object_new (META_TYPE_SEAT_NATIVE,
|
||||||
|
"backend", backend,
|
||||||
"seat-id", seat_id,
|
"seat-id", seat_id,
|
||||||
"flags", flags,
|
"flags", flags,
|
||||||
NULL));
|
NULL));
|
||||||
|
@ -34,7 +34,9 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "backends/meta-cursor-tracker-private.h"
|
#include "backends/meta-cursor-tracker-private.h"
|
||||||
|
#include "backends/native/meta-backend-native-private.h"
|
||||||
#include "backends/native/meta-barrier-native.h"
|
#include "backends/native/meta-barrier-native.h"
|
||||||
|
#include "backends/native/meta-device-pool.h"
|
||||||
#include "backends/native/meta-input-thread.h"
|
#include "backends/native/meta-input-thread.h"
|
||||||
#include "backends/native/meta-virtual-input-device-native.h"
|
#include "backends/native/meta-virtual-input-device-native.h"
|
||||||
#include "clutter/clutter-mutter.h"
|
#include "clutter/clutter-mutter.h"
|
||||||
@ -116,11 +118,17 @@ enum
|
|||||||
|
|
||||||
static guint signals[N_SIGNALS] = { 0 };
|
static guint signals[N_SIGNALS] = { 0 };
|
||||||
|
|
||||||
|
typedef struct _MetaSeatImplPrivate
|
||||||
|
{
|
||||||
|
GHashTable *device_files;
|
||||||
|
} MetaSeatImplPrivate;
|
||||||
|
|
||||||
static void meta_seat_impl_initable_iface_init (GInitableIface *iface);
|
static void meta_seat_impl_initable_iface_init (GInitableIface *iface);
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (MetaSeatImpl, meta_seat_impl, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE (MetaSeatImpl, meta_seat_impl, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||||
meta_seat_impl_initable_iface_init))
|
meta_seat_impl_initable_iface_init)
|
||||||
|
G_ADD_PRIVATE (MetaSeatImpl))
|
||||||
|
|
||||||
static void process_events (MetaSeatImpl *seat_impl);
|
static void process_events (MetaSeatImpl *seat_impl);
|
||||||
void meta_seat_impl_constrain_pointer (MetaSeatImpl *seat_impl,
|
void meta_seat_impl_constrain_pointer (MetaSeatImpl *seat_impl,
|
||||||
@ -2565,32 +2573,36 @@ process_events (MetaSeatImpl *seat_impl)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
open_restricted (const char *path,
|
open_restricted (const char *path,
|
||||||
int flags,
|
int open_flags,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
MetaSeatImpl *seat_impl = user_data;
|
||||||
|
MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
|
||||||
|
MetaBackend *backend = meta_seat_native_get_backend (seat_impl->seat_native);
|
||||||
|
MetaDevicePool *device_pool =
|
||||||
|
meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
|
||||||
|
MetaDeviceFileFlags flags;
|
||||||
|
g_autoptr (GError) error = NULL;
|
||||||
|
MetaDeviceFile *device_file;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (device_open_callback)
|
flags = META_DEVICE_FILE_FLAG_NONE;
|
||||||
{
|
if (!(open_flags & (O_RDWR | O_WRONLY)))
|
||||||
GError *error = NULL;
|
flags |= META_DEVICE_FILE_FLAG_READ_ONLY;
|
||||||
|
|
||||||
fd = device_open_callback (path, flags, device_callback_data, &error);
|
if (!g_str_has_prefix (path, "/sys/"))
|
||||||
|
flags |= META_DEVICE_FILE_FLAG_TAKE_CONTROL;
|
||||||
|
|
||||||
if (fd < 0)
|
device_file = meta_device_pool_open (device_pool, path, flags, &error);
|
||||||
{
|
if (!device_file)
|
||||||
g_warning ("Could not open device %s: %s", path, error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
fd = open (path, O_RDWR | O_NONBLOCK);
|
g_warning ("Could not open device %s: %s", path, error->message);
|
||||||
if (fd < 0)
|
return -1;
|
||||||
{
|
|
||||||
g_warning ("Could not open device %s: %s", path, strerror (errno));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fd = meta_device_file_get_fd (device_file);
|
||||||
|
g_hash_table_insert (priv->device_files, GINT_TO_POINTER (fd), device_file);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2598,10 +2610,10 @@ static void
|
|||||||
close_restricted (int fd,
|
close_restricted (int fd,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
if (device_close_callback)
|
MetaSeatImpl *seat_impl = user_data;
|
||||||
device_close_callback (fd, device_callback_data);
|
MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
|
||||||
else
|
|
||||||
close (fd);
|
g_hash_table_remove (priv->device_files, GINT_TO_POINTER (fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct libinput_interface libinput_interface = {
|
static const struct libinput_interface libinput_interface = {
|
||||||
@ -2709,10 +2721,16 @@ init_libinput (MetaSeatImpl *seat_impl,
|
|||||||
static gpointer
|
static gpointer
|
||||||
input_thread (MetaSeatImpl *seat_impl)
|
input_thread (MetaSeatImpl *seat_impl)
|
||||||
{
|
{
|
||||||
|
MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
|
||||||
struct xkb_keymap *xkb_keymap;
|
struct xkb_keymap *xkb_keymap;
|
||||||
|
|
||||||
g_main_context_push_thread_default (seat_impl->input_context);
|
g_main_context_push_thread_default (seat_impl->input_context);
|
||||||
|
|
||||||
|
priv->device_files =
|
||||||
|
g_hash_table_new_full (NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
(GDestroyNotify) meta_device_file_release);
|
||||||
|
|
||||||
if (!(seat_impl->flags & META_SEAT_NATIVE_FLAG_NO_LIBINPUT))
|
if (!(seat_impl->flags & META_SEAT_NATIVE_FLAG_NO_LIBINPUT))
|
||||||
{
|
{
|
||||||
g_autoptr (GError) error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
@ -2868,6 +2886,7 @@ static gboolean
|
|||||||
destroy_in_impl (GTask *task)
|
destroy_in_impl (GTask *task)
|
||||||
{
|
{
|
||||||
MetaSeatImpl *seat_impl = g_task_get_source_object (task);
|
MetaSeatImpl *seat_impl = g_task_get_source_object (task);
|
||||||
|
MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
|
||||||
gboolean numlock_active;
|
gboolean numlock_active;
|
||||||
|
|
||||||
g_slist_foreach (seat_impl->devices,
|
g_slist_foreach (seat_impl->devices,
|
||||||
@ -2892,6 +2911,8 @@ destroy_in_impl (GTask *task)
|
|||||||
|
|
||||||
meta_seat_impl_clear_repeat_source (seat_impl);
|
meta_seat_impl_clear_repeat_source (seat_impl);
|
||||||
|
|
||||||
|
g_clear_pointer (&priv->device_files, g_hash_table_destroy);
|
||||||
|
|
||||||
g_main_loop_quit (seat_impl->input_loop);
|
g_main_loop_quit (seat_impl->input_loop);
|
||||||
g_task_return_boolean (task, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ enum
|
|||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_SEAT_ID,
|
PROP_SEAT_ID,
|
||||||
PROP_FLAGS,
|
PROP_FLAGS,
|
||||||
|
PROP_BACKEND,
|
||||||
N_PROPS,
|
N_PROPS,
|
||||||
|
|
||||||
/* This property is overridden */
|
/* This property is overridden */
|
||||||
@ -193,6 +194,9 @@ meta_seat_native_set_property (GObject *object,
|
|||||||
case PROP_FLAGS:
|
case PROP_FLAGS:
|
||||||
seat_native->flags = g_value_get_flags (value);
|
seat_native->flags = g_value_get_flags (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_BACKEND:
|
||||||
|
seat_native->backend = g_value_get_object (value);
|
||||||
|
break;
|
||||||
case PROP_TOUCH_MODE:
|
case PROP_TOUCH_MODE:
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
@ -218,6 +222,9 @@ meta_seat_native_get_property (GObject *object,
|
|||||||
case PROP_FLAGS:
|
case PROP_FLAGS:
|
||||||
g_value_set_flags (value, seat_native->flags);
|
g_value_set_flags (value, seat_native->flags);
|
||||||
break;
|
break;
|
||||||
|
case PROP_BACKEND:
|
||||||
|
g_value_set_object (value, seat_native->backend);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
}
|
}
|
||||||
@ -400,6 +407,14 @@ meta_seat_native_class_init (MetaSeatNativeClass *klass)
|
|||||||
G_PARAM_READWRITE |
|
G_PARAM_READWRITE |
|
||||||
G_PARAM_CONSTRUCT_ONLY);
|
G_PARAM_CONSTRUCT_ONLY);
|
||||||
|
|
||||||
|
props[PROP_BACKEND] =
|
||||||
|
g_param_spec_object ("backend",
|
||||||
|
"Backend",
|
||||||
|
"Backend",
|
||||||
|
META_TYPE_BACKEND,
|
||||||
|
G_PARAM_READWRITE |
|
||||||
|
G_PARAM_CONSTRUCT_ONLY);
|
||||||
|
|
||||||
g_object_class_install_properties (object_class, N_PROPS, props);
|
g_object_class_install_properties (object_class, N_PROPS, props);
|
||||||
|
|
||||||
g_object_class_override_property (object_class, PROP_TOUCH_MODE,
|
g_object_class_override_property (object_class, PROP_TOUCH_MODE,
|
||||||
@ -571,6 +586,12 @@ meta_seat_native_get_barrier_manager (MetaSeatNative *seat)
|
|||||||
return meta_seat_impl_get_barrier_manager (seat->impl);
|
return meta_seat_impl_get_barrier_manager (seat->impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MetaBackend *
|
||||||
|
meta_seat_native_get_backend (MetaSeatNative *seat_native)
|
||||||
|
{
|
||||||
|
return seat_native->backend;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
|
meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
|
||||||
MetaPointerConstraintImpl *constraint_impl)
|
MetaPointerConstraintImpl *constraint_impl)
|
||||||
|
@ -42,6 +42,8 @@ struct _MetaSeatNative
|
|||||||
{
|
{
|
||||||
ClutterSeat parent_instance;
|
ClutterSeat parent_instance;
|
||||||
|
|
||||||
|
MetaBackend *backend;
|
||||||
|
|
||||||
MetaSeatImpl *impl;
|
MetaSeatImpl *impl;
|
||||||
char *seat_id;
|
char *seat_id;
|
||||||
MetaSeatNativeFlag flags;
|
MetaSeatNativeFlag flags;
|
||||||
@ -118,6 +120,8 @@ void meta_seat_native_release_touch_slots (MetaSeatNative *seat,
|
|||||||
|
|
||||||
MetaBarrierManagerNative * meta_seat_native_get_barrier_manager (MetaSeatNative *seat);
|
MetaBarrierManagerNative * meta_seat_native_get_barrier_manager (MetaSeatNative *seat);
|
||||||
|
|
||||||
|
MetaBackend * meta_seat_native_get_backend (MetaSeatNative *seat);
|
||||||
|
|
||||||
void meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
|
void meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
|
||||||
MetaPointerConstraintImpl *constraint_impl);
|
MetaPointerConstraintImpl *constraint_impl);
|
||||||
MetaCursorRenderer * meta_seat_native_maybe_ensure_cursor_renderer (MetaSeatNative *seat,
|
MetaCursorRenderer * meta_seat_native_maybe_ensure_cursor_renderer (MetaSeatNative *seat,
|
||||||
|
Loading…
Reference in New Issue
Block a user