1
0
Fork 0
mutter-performance-source/src/backends/native/meta-seat-impl.h

255 lines
11 KiB
C
Raw Normal View History

/*
* Copyright (C) 2010 Intel Corp.
* Copyright (C) 2014 Jonas Ådahl
* Copyright (C) 2016 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Damien Lespiau <damien.lespiau@intel.com>
* Author: Jonas Ådahl <jadahl@gmail.com>
*/
#ifndef META_SEAT_IMPL_H
#define META_SEAT_IMPL_H
#ifndef META_INPUT_THREAD_H_INSIDE
#error "This header cannot be included directly. Use "backends/native/meta-input-thread.h""
#endif /* META_INPUT_THREAD_H_INSIDE */
#include <gudev/gudev.h>
#include <libinput.h>
#include <linux/input-event-codes.h>
#include "backends/meta-input-settings-private.h"
#include "backends/meta-viewport-info.h"
#include "backends/native/meta-backend-native-types.h"
#include "backends/native/meta-barrier-native.h"
#include "backends/native/meta-cursor-renderer-native.h"
#include "backends/native/meta-keymap-native.h"
#include "backends/native/meta-pointer-constraint-native.h"
#include "backends/native/meta-xkb-utils.h"
#include "clutter/clutter.h"
typedef struct _MetaTouchState MetaTouchState;
typedef struct _MetaSeatImpl MetaSeatImpl;
typedef struct _MetaEventSource MetaEventSource;
struct _MetaTouchState
{
MetaSeatImpl *seat_impl;
int device_slot;
int seat_slot;
graphene_point_t coords;
};
struct _MetaSeatImpl
{
GObject parent_instance;
GMainContext *main_context;
GMainContext *input_context;
GMainLoop *input_loop;
GThread *input_thread;
GMutex init_mutex;
GCond init_cond;
MetaSeatNative *seat_native;
char *seat_id;
MetaSeatNativeFlag flags;
MetaEventSource *event_source;
struct libinput *libinput;
GRWLock state_lock;
GSList *devices;
GHashTable *tools;
ClutterInputDevice *core_pointer;
ClutterInputDevice *core_keyboard;
GHashTable *touch_states;
GHashTable *cursor_renderers;
struct xkb_state *xkb;
xkb_led_index_t caps_lock_led;
xkb_led_index_t num_lock_led;
xkb_led_index_t scroll_lock_led;
xkb_layout_index_t layout_idx;
uint32_t button_state;
int button_count[KEY_CNT];
MetaBarrierManagerNative *barrier_manager;
MetaPointerConstraintImpl *pointer_constraint;
MetaKeymapNative *keymap;
MetaInputSettings *input_settings;
MetaViewportInfo *viewports;
gboolean tablet_mode_switch_state;
gboolean has_touchscreen;
gboolean has_tablet_switch;
backends/native: Disable touch-mode with pointer presence The original implementation of ::touch-mode tested for keyboard presence to know whether the OSK and other touch-only features were enabled. However that didn't pan out, every webcam, card reader and kitchen sink like to live a second life as EV_KEY devices. This made the detection of actual external keyboards a much harder task than it sounds, and was thus removed in commit f8e2234ce59fbb. Try a different approach here, and test for pointer devices, it doesn't matter if internal or external devices, the rationales: - It is significantly easier to get this right, there's virtually no devices with abs/rel axes that don't try to be a real input device of some sorts. - It's not as good as testing for keyboard presence, but it's the next best thing. These usually come in pairs, except in weird setups. - It is better than not having anything for a number of situations: - Non-convertible laptops with a touchscreen will get touch-mode disabled due to touchpad presence (plus keyboard). There's been complains about OSK triggering with those. - Same for desktop machines with USB touchscreens, the mouse (and presumably keyboard) attached would make touch-mode get in the middle. - Convertible laptops with a broken tablet-mode switch get a chance to work on tablet modes that do disable input devices (e.g. detachable keyboards, or via firmware) - Kiosk machines, tablets, and other devices that have a touchscreen but will not regularly have a mouse/keyboard will get the touch-mode enabled. All in all, this seems to cover more situations the way we expect it, there's only one situation that the OSK would show where it might not be desirable, and one that might not show when it better should: - Tablets and kiosk machines that get one keyboard plugged, but not a mouse, will still show the OSK, despite being able to type right away. - Convertible laptops with broken/unreliable tablet-mode switch (e.g. ignored by the kernel) rely entirely on the device/firmware characteristics to work. If after folding into tablet mode the touchpad remains active, touch-mode will not turn on. Fixing the tablet-mode switch on these devices should be preferred, as that'll also make libinput magically disable the touchpad. The latter can be worked around with the a11y toggle. The former is merely inconvenient, and nothing prevents the user from plugging a mouse in addition. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1710>
2021-02-04 23:33:56 +00:00
gboolean has_pointer;
gboolean touch_mode;
gboolean input_thread_initialized;
/* keyboard repeat */
gboolean repeat;
uint32_t repeat_delay;
uint32_t repeat_interval;
uint32_t repeat_key;
uint32_t repeat_count;
ClutterInputDevice *repeat_device;
GSource *repeat_source;
float pointer_x;
float pointer_y;
/* Emulation of discrete scroll events out of smooth ones */
float accum_scroll_dx;
float accum_scroll_dy;
gboolean released;
};
#define META_TYPE_SEAT_IMPL meta_seat_impl_get_type ()
G_DECLARE_FINAL_TYPE (MetaSeatImpl, meta_seat_impl,
META, SEAT_IMPL, GObject)
MetaSeatImpl * meta_seat_impl_new (MetaSeatNative *seat_native,
const char *seat_id,
MetaSeatNativeFlag flags);
void meta_seat_impl_destroy (MetaSeatImpl *seat_impl);
void meta_seat_impl_run_input_task (MetaSeatImpl *seat_impl,
GTask *task,
GSourceFunc dispatch_func);
void meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *device,
uint64_t time_us,
uint32_t key,
uint32_t state,
gboolean update_keys);
void meta_seat_impl_notify_relative_motion_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
uint64_t time_us,
float dx,
float dy,
float dx_unaccel,
float dy_unaccel);
void meta_seat_impl_notify_absolute_motion_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
uint64_t time_us,
float x,
float y,
double *axes);
void meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
uint64_t time_us,
uint32_t button,
uint32_t state);
void meta_seat_impl_notify_scroll_continuous_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
uint64_t time_us,
double dx,
double dy,
ClutterScrollSource source,
ClutterScrollFinishFlags flags);
void meta_seat_impl_notify_discrete_scroll_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
uint64_t time_us,
double discrete_dx,
double discrete_dy,
ClutterScrollSource source);
void meta_seat_impl_notify_touch_event_in_impl (MetaSeatImpl *seat_impl,
ClutterInputDevice *input_device,
ClutterEventType evtype,
uint64_t time_us,
int slot,
double x,
double y);
void meta_seat_impl_sync_leds_in_impl (MetaSeatImpl *seat_impl);
MetaTouchState * meta_seat_impl_acquire_touch_state_in_impl (MetaSeatImpl *seat_impl,
int seat_slot);
MetaTouchState * meta_seat_impl_lookup_touch_state_in_impl (MetaSeatImpl *seat_impl,
int seat_slot);
void meta_seat_impl_release_touch_state_in_impl (MetaSeatImpl *seat_impl,
int seat_slot);
void meta_seat_impl_update_xkb_state_in_impl (MetaSeatImpl *seat_impl);
void meta_seat_impl_release_devices (MetaSeatImpl *seat_impl);
void meta_seat_impl_reclaim_devices (MetaSeatImpl *seat_impl);
struct xkb_state * meta_seat_impl_get_xkb_state_in_impl (MetaSeatImpl *seat_impl);
void meta_seat_impl_set_keyboard_map (MetaSeatImpl *seat_impl,
struct xkb_keymap *keymap);
void meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat_impl,
xkb_layout_index_t idx);
void meta_seat_impl_set_keyboard_repeat_in_impl (MetaSeatImpl *seat_impl,
gboolean repeat,
uint32_t delay,
uint32_t interval);
MetaBarrierManagerNative * meta_seat_impl_get_barrier_manager (MetaSeatImpl *seat_impl);
void meta_seat_impl_set_pointer_constraint (MetaSeatImpl *seat_impl,
MetaPointerConstraintImpl *constraint_impl);
void meta_seat_impl_set_viewports (MetaSeatImpl *seat_impl,
MetaViewportInfo *viewports);
void meta_seat_impl_warp_pointer (MetaSeatImpl *seat_impl,
int x,
int y);
gboolean meta_seat_impl_query_state (MetaSeatImpl *seat_impl,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
graphene_point_t *coords,
ClutterModifierType *modifiers);
ClutterInputDevice * meta_seat_impl_get_pointer (MetaSeatImpl *seat_impl);
ClutterInputDevice * meta_seat_impl_get_keyboard (MetaSeatImpl *seat_impl);
GSList * meta_seat_impl_get_devices_in_impl (MetaSeatImpl *seat_impl);
MetaKeymapNative * meta_seat_impl_get_keymap (MetaSeatImpl *seat_impl);
void meta_seat_impl_notify_kbd_a11y_flags_changed_in_impl (MetaSeatImpl *seat_impl,
MetaKeyboardA11yFlags new_flags,
MetaKeyboardA11yFlags what_changed);
void meta_seat_impl_notify_kbd_a11y_mods_state_changed_in_impl (MetaSeatImpl *seat_impl,
xkb_mod_mask_t new_latched_mods,
xkb_mod_mask_t new_locked_mods);
void meta_seat_impl_notify_bell_in_impl (MetaSeatImpl *seat_impl);
MetaInputSettings * meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl);
void meta_seat_impl_queue_main_thread_idle (MetaSeatImpl *seat_impl,
GSourceFunc func,
gpointer user_data,
GDestroyNotify destroy_notify);
#endif /* META_SEAT_IMPL_H */