backends/x11: Implement X11-specific MetaInputSettings
This goes through modifying XI2 device properties, either common ones (eg. set on every device) or those specific to the libinput X11 driver. Keyboard repeat/rate are set through core and XKB APIs. https://bugzilla.gnome.org/show_bug.cgi?id=739397
This commit is contained in:
parent
460e1fd7ca
commit
3c06f2dc90
@ -95,6 +95,8 @@ libmutter_la_SOURCES = \
|
||||
backends/x11/meta-cursor-renderer-x11.h \
|
||||
backends/x11/meta-idle-monitor-xsync.c \
|
||||
backends/x11/meta-idle-monitor-xsync.h \
|
||||
backends/x11/meta-input-settings-x11.c \
|
||||
backends/x11/meta-input-settings-x11.h \
|
||||
backends/x11/meta-monitor-manager-xrandr.c \
|
||||
backends/x11/meta-monitor-manager-xrandr.h \
|
||||
core/meta-accel-parse.c \
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "meta-backend-private.h"
|
||||
#include "meta-input-settings-private.h"
|
||||
#include "x11/meta-input-settings-x11.h"
|
||||
|
||||
#include <meta/util.h>
|
||||
|
||||
@ -603,5 +604,8 @@ meta_input_settings_init (MetaInputSettings *settings)
|
||||
MetaInputSettings *
|
||||
meta_input_settings_create (void)
|
||||
{
|
||||
if (!meta_is_wayland_compositor ())
|
||||
return g_object_new (META_TYPE_INPUT_SETTINGS_X11, NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
226
src/backends/x11/meta-input-settings-x11.c
Normal file
226
src/backends/x11/meta-input-settings-x11.c
Normal file
@ -0,0 +1,226 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 Red Hat
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "meta-backend-x11.h"
|
||||
#include "meta-input-settings-x11.h"
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#include <X11/XKBlib.h>
|
||||
|
||||
#include <meta/errors.h>
|
||||
|
||||
G_DEFINE_TYPE (MetaInputSettingsX11, meta_input_settings_x11, META_TYPE_INPUT_SETTINGS)
|
||||
|
||||
static void
|
||||
change_property (ClutterInputDevice *device,
|
||||
const gchar *property,
|
||||
Atom type,
|
||||
int format,
|
||||
void *data,
|
||||
gulong nitems)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
|
||||
gulong nitems_ret, bytes_after_ret;
|
||||
int rc, device_id, format_ret;
|
||||
Atom property_atom, type_ret;
|
||||
guchar *data_ret;
|
||||
|
||||
property_atom = XInternAtom (xdisplay, property, False);
|
||||
device_id = clutter_input_device_get_device_id (device);
|
||||
|
||||
rc = XIGetProperty (xdisplay, device_id, property_atom,
|
||||
0, 0, False, type, &type_ret, &format_ret,
|
||||
&nitems_ret, &bytes_after_ret, &data_ret);
|
||||
|
||||
meta_XFree (data_ret);
|
||||
|
||||
if (rc == Success && type_ret == type && format_ret == format)
|
||||
XIChangeProperty (xdisplay, device_id, property_atom, type,
|
||||
format, XIPropModeReplace, data, nitems);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_send_events (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
GDesktopDeviceSendEvents mode)
|
||||
{
|
||||
guchar values[2] = { 0 }; /* disabled, disabled-on-external-mouse */
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED:
|
||||
values[0] = 1;
|
||||
break;
|
||||
case G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
|
||||
values[1] = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
change_property (device, "libinput Send Events Mode Enabled",
|
||||
XA_INTEGER, 8, &values, 2);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_matrix (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
gfloat matrix[6])
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
|
||||
gfloat full_matrix[9] = { matrix[0], matrix[1], matrix[2],
|
||||
matrix[3], matrix[4], matrix[5],
|
||||
0, 0, 1 };
|
||||
|
||||
change_property (device, "Coordinate Transformation Matrix",
|
||||
XInternAtom (xdisplay, "FLOAT", False),
|
||||
32, &full_matrix, 9);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_speed (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
gdouble speed)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
|
||||
gfloat value = speed;
|
||||
|
||||
change_property (device, "libinput Accel Speed",
|
||||
XInternAtom (xdisplay, "FLOAT", False),
|
||||
32, &value, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_left_handed (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
gboolean enabled)
|
||||
{
|
||||
guchar value = (enabled) ? 1 : 0;
|
||||
|
||||
change_property (device, "libinput Left Handed Enabled",
|
||||
XA_INTEGER, 8, &value, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_tap_enabled (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
gboolean enabled)
|
||||
{
|
||||
guchar value = (enabled) ? 1 : 0;
|
||||
|
||||
change_property (device, "libinput Tapping Enabled",
|
||||
XA_INTEGER, 8, &value, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_invert_scroll (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
gboolean inverted)
|
||||
{
|
||||
guchar value = (inverted) ? 1 : 0;
|
||||
|
||||
change_property (device, "libinput Natural Scrolling Enabled",
|
||||
XA_INTEGER, 8, &value, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_scroll_method (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
GDesktopTouchpadScrollMethod mode)
|
||||
{
|
||||
guchar values[3] = { 0 }; /* 2fg, edge, button. The last value is unused */
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case G_DESKTOP_TOUCHPAD_SCROLL_METHOD_DISABLED:
|
||||
break;
|
||||
case G_DESKTOP_TOUCHPAD_SCROLL_METHOD_EDGE_SCROLLING:
|
||||
values[1] = 1;
|
||||
break;
|
||||
case G_DESKTOP_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING:
|
||||
values[0] = 1;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
change_property (device, "libinput Scroll Method Enabled",
|
||||
XA_INTEGER, 8, &values, 3);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_scroll_button (MetaInputSettings *settings,
|
||||
ClutterInputDevice *device,
|
||||
guint button)
|
||||
{
|
||||
change_property (device, "libinput Scroll Method Enabled",
|
||||
XA_INTEGER, 32, &button, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_set_keyboard_repeat (MetaInputSettings *settings,
|
||||
gboolean enabled,
|
||||
guint delay,
|
||||
guint interval)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
XAutoRepeatOn (xdisplay);
|
||||
XkbSetAutoRepeatRate (xdisplay, XkbUseCoreKbd, delay, interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
XAutoRepeatOff (xdisplay);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_class_init (MetaInputSettingsX11Class *klass)
|
||||
{
|
||||
MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
|
||||
|
||||
input_settings_class->set_send_events = meta_input_settings_x11_set_send_events;
|
||||
input_settings_class->set_matrix = meta_input_settings_x11_set_matrix;
|
||||
input_settings_class->set_speed = meta_input_settings_x11_set_speed;
|
||||
input_settings_class->set_left_handed = meta_input_settings_x11_set_left_handed;
|
||||
input_settings_class->set_tap_enabled = meta_input_settings_x11_set_tap_enabled;
|
||||
input_settings_class->set_invert_scroll = meta_input_settings_x11_set_invert_scroll;
|
||||
input_settings_class->set_scroll_method = meta_input_settings_x11_set_scroll_method;
|
||||
input_settings_class->set_scroll_button = meta_input_settings_x11_set_scroll_button;
|
||||
input_settings_class->set_keyboard_repeat = meta_input_settings_x11_set_keyboard_repeat;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_input_settings_x11_init (MetaInputSettingsX11 *settings)
|
||||
{
|
||||
}
|
49
src/backends/x11/meta-input-settings-x11.h
Normal file
49
src/backends/x11/meta-input-settings-x11.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/*
|
||||
* Copyright 2014 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef META_INPUT_SETTINGS_X11_H
|
||||
#define META_INPUT_SETTINGS_X11_H
|
||||
|
||||
#include "meta-input-settings-private.h"
|
||||
|
||||
#define META_TYPE_INPUT_SETTINGS_X11 (meta_input_settings_x11_get_type ())
|
||||
#define META_INPUT_SETTINGS_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_INPUT_SETTINGS_X11, MetaInputSettingsX11))
|
||||
#define META_INPUT_SETTINGS_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_INPUT_SETTINGS_X11, MetaInputSettingsX11Class))
|
||||
#define META_IS_INPUT_SETTINGS_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_INPUT_SETTINGS_X11))
|
||||
#define META_IS_INPUT_SETTINGS_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_INPUT_SETTINGS_X11))
|
||||
#define META_INPUT_SETTINGS_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_INPUT_SETTINGS_X11, MetaInputSettingsX11Class))
|
||||
|
||||
typedef struct _MetaInputSettingsX11 MetaInputSettingsX11;
|
||||
typedef struct _MetaInputSettingsX11Class MetaInputSettingsX11Class;
|
||||
|
||||
struct _MetaInputSettingsX11
|
||||
{
|
||||
MetaInputSettings parent_instance;
|
||||
};
|
||||
|
||||
struct _MetaInputSettingsX11Class
|
||||
{
|
||||
MetaInputSettingsClass parent_class;
|
||||
};
|
||||
|
||||
GType meta_input_settings_x11_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#endif /* META_INPUT_SETTINGS_X11_H */
|
Loading…
Reference in New Issue
Block a user