diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index a199f1af4..7b05d72eb 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -144,6 +144,7 @@ struct _MetaBackendPrivate gboolean is_pointer_position_initialized; guint device_update_idle_id; + guint keymap_state_changed_id; GHashTable *device_monitors; @@ -178,6 +179,14 @@ meta_backend_finalize (GObject *object) MetaBackend *backend = META_BACKEND (object); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); + if (priv->keymap_state_changed_id) + { + ClutterKeymap *keymap; + + keymap = clutter_backend_get_keymap (priv->clutter_backend); + g_signal_handler_disconnect (keymap, priv->keymap_state_changed_id); + } + g_list_free_full (priv->gpus, g_object_unref); g_clear_object (&priv->monitor_manager); @@ -491,6 +500,7 @@ meta_backend_real_post_init (MetaBackend *backend) { MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); ClutterDeviceManager *device_manager = clutter_device_manager_get_default (); + ClutterKeymap *keymap = clutter_backend_get_keymap (priv->clutter_backend); priv->stage = meta_stage_new (backend); clutter_actor_realize (priv->stage); @@ -517,6 +527,15 @@ meta_backend_real_post_init (MetaBackend *backend) priv->input_settings = meta_backend_create_input_settings (backend); + if (priv->input_settings) + { + priv->keymap_state_changed_id = + g_signal_connect_swapped (keymap, "state-changed", + G_CALLBACK (meta_input_settings_maybe_save_numlock_state), + priv->input_settings); + meta_input_settings_maybe_restore_numlock_state (priv->input_settings); + } + #ifdef HAVE_REMOTE_DESKTOP priv->remote_access_controller = g_object_new (META_TYPE_REMOTE_ACCESS_CONTROLLER, NULL); diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h index 18f2bdc4d..a035db78f 100644 --- a/src/backends/meta-input-settings-private.h +++ b/src/backends/meta-input-settings-private.h @@ -144,4 +144,7 @@ WacomDevice * meta_input_settings_get_tablet_wacom_device (MetaInputSettings *se ClutterInputDevice *device); #endif +void meta_input_settings_maybe_save_numlock_state (MetaInputSettings *input_settings); +void meta_input_settings_maybe_restore_numlock_state (MetaInputSettings *input_settings); + #endif /* META_INPUT_SETTINGS_PRIVATE_H */ diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index 847ba1bea..3ebf826ac 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -1152,6 +1152,8 @@ meta_input_settings_changed_cb (GSettings *settings, strcmp (key, "repeat-interval") == 0 || strcmp (key, "delay") == 0) update_keyboard_repeat (input_settings); + else if (strcmp (key, "remember-numlock-state") == 0) + meta_input_settings_maybe_save_numlock_state (input_settings); } } @@ -2609,3 +2611,39 @@ meta_input_settings_get_pad_action_label (MetaInputSettings *input_settings, return NULL; } + +void +meta_input_settings_maybe_save_numlock_state (MetaInputSettings *input_settings) +{ + MetaInputSettingsPrivate *priv; + ClutterKeymap *keymap; + gboolean numlock_state; + + priv = meta_input_settings_get_instance_private (input_settings); + + if (!g_settings_get_boolean (priv->keyboard_settings, "remember-numlock-state")) + return; + + keymap = clutter_backend_get_keymap (clutter_get_default_backend ()); + numlock_state = clutter_keymap_get_num_lock_state (keymap); + + if (numlock_state == g_settings_get_boolean (priv->keyboard_settings, "numlock-state")) + return; + + g_settings_set_boolean (priv->keyboard_settings, "numlock-state", numlock_state); +} + +void +meta_input_settings_maybe_restore_numlock_state (MetaInputSettings *input_settings) +{ + MetaInputSettingsPrivate *priv; + gboolean numlock_state; + + priv = meta_input_settings_get_instance_private (input_settings); + + if (!g_settings_get_boolean (priv->keyboard_settings, "remember-numlock-state")) + return; + + numlock_state = g_settings_get_boolean (priv->keyboard_settings, "numlock-state"); + meta_backend_set_numlock (meta_get_backend (), numlock_state); +} diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index f34437e6d..d285d61f2 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -814,6 +814,7 @@ void meta_backend_native_resume (MetaBackendNative *native) meta_backend_get_monitor_manager (backend); MetaMonitorManagerKms *monitor_manager_kms = META_MONITOR_MANAGER_KMS (monitor_manager); + MetaInputSettings *input_settings; MetaIdleMonitor *idle_monitor; meta_monitor_manager_kms_resume (monitor_manager_kms); @@ -827,4 +828,7 @@ void meta_backend_native_resume (MetaBackendNative *native) idle_monitor = meta_backend_get_idle_monitor (backend, 0); meta_idle_monitor_reset_idletime (idle_monitor); + + input_settings = meta_backend_get_input_settings (backend); + meta_input_settings_maybe_restore_numlock_state (input_settings); } diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c index 8b23d76ce..291faa1e9 100644 --- a/src/wayland/meta-wayland-keyboard.c +++ b/src/wayland/meta-wayland-keyboard.c @@ -65,19 +65,11 @@ #endif #define GSD_KEYBOARD_SCHEMA "org.gnome.settings-daemon.peripherals.keyboard" -typedef enum -{ - GSD_KEYBOARD_NUM_LOCK_STATE_UNKNOWN, - GSD_KEYBOARD_NUM_LOCK_STATE_ON, - GSD_KEYBOARD_NUM_LOCK_STATE_OFF -} GsdKeyboardNumLockState; G_DEFINE_TYPE (MetaWaylandKeyboard, meta_wayland_keyboard, META_TYPE_WAYLAND_INPUT_DEVICE) static void meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard); -static void meta_wayland_keyboard_set_numlock (MetaWaylandKeyboard *keyboard, - gboolean numlock_state); static void notify_modifiers (MetaWaylandKeyboard *keyboard); static guint evdev_code (const ClutterKeyEvent *event); @@ -404,110 +396,6 @@ notify_modifiers (MetaWaylandKeyboard *keyboard) xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE)); } -static void -numlock_set_xkb_state (MetaWaylandKeyboard *keyboard, - GsdKeyboardNumLockState state) -{ - MetaBackend *backend = meta_get_backend (); - gboolean numlock_state; - - if (state != GSD_KEYBOARD_NUM_LOCK_STATE_ON && - state != GSD_KEYBOARD_NUM_LOCK_STATE_OFF) - return; - - numlock_state = (state == GSD_KEYBOARD_NUM_LOCK_STATE_ON); - meta_verbose ("set numlock state %s\n", (numlock_state ? "ON" : "OFF")); - meta_backend_set_numlock (backend, numlock_state); - meta_wayland_keyboard_set_numlock (keyboard, numlock_state); -} - -static void -maybe_restore_numlock_state (MetaWaylandKeyboard *keyboard) -{ - gboolean remember_numlock; - - if (!keyboard->gsd_settings) - return; - - /* We are cheating for now, we use g-s-d settings... */ - remember_numlock = g_settings_get_boolean (keyboard->gsd_settings, - "remember-numlock-state"); - - if (remember_numlock) - { - GsdKeyboardNumLockState state; - - state = g_settings_get_enum (keyboard->gsd_settings, "numlock-state"); - numlock_set_xkb_state (keyboard, state); - } -} - -static void -maybe_save_numlock_state (MetaWaylandKeyboard *keyboard) -{ -#ifdef HAVE_NATIVE_BACKEND - MetaWaylandXkbInfo *xkb_info = &keyboard->xkb_info; - GsdKeyboardNumLockState numlock_state; - int numlock_active; - - if (!META_IS_BACKEND_NATIVE (meta_get_backend ())) - return; - - if (!xkb_info->state) - return; - - if (!keyboard->gsd_settings) - return; - - if (!g_settings_get_boolean (keyboard->gsd_settings, "remember-numlock-state")) - return; - - numlock_active = xkb_state_mod_name_is_active(xkb_info->state, - "Mod2", - XKB_STATE_MODS_LOCKED); - switch (numlock_active) - { - case -1: - numlock_state = GSD_KEYBOARD_NUM_LOCK_STATE_UNKNOWN; - break; - case 0: - numlock_state = GSD_KEYBOARD_NUM_LOCK_STATE_OFF; - break; - default: - numlock_state = GSD_KEYBOARD_NUM_LOCK_STATE_ON; - break; - } - g_settings_set_enum (keyboard->gsd_settings, "numlock-state", numlock_state); -#endif -} - -static void -meta_wayland_keyboard_set_numlock (MetaWaylandKeyboard *keyboard, - gboolean numlock_state) -{ - MetaWaylandXkbInfo *xkb_info = &keyboard->xkb_info; - xkb_mod_mask_t latched, locked, group, depressed; - xkb_mod_mask_t numlock; - - meta_verbose ("backend numlock state %s\n", (numlock_state ? "ON" : "OFF")); - - latched = xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_LATCHED); - locked = xkb_state_serialize_mods (xkb_info->state, XKB_STATE_MODS_LOCKED); - group = xkb_state_serialize_layout (xkb_info->state, XKB_STATE_LAYOUT_EFFECTIVE); - depressed = xkb_state_serialize_mods(xkb_info->state, XKB_STATE_DEPRESSED); - numlock = (1 << xkb_keymap_mod_get_index(xkb_info->keymap, "Mod2")); - - if (numlock_state == TRUE) - locked |= numlock; - else - locked &= ~numlock; - - xkb_state_update_mask (xkb_info->state, depressed, latched, locked, 0, 0, group); - kbd_a11y_apply_mask (keyboard); - - notify_modifiers (keyboard); -} - static void meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard) { @@ -615,16 +503,6 @@ notify_key_repeat (MetaWaylandKeyboard *keyboard) } } -static void -remember_numlock_state_changed (GSettings *settings, - const char *key, - gpointer data) -{ - MetaWaylandKeyboard *keyboard = data; - - maybe_save_numlock_state (keyboard); -} - static void settings_changed (GSettings *settings, const char *key, @@ -678,24 +556,11 @@ void meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard) { MetaBackend *backend = meta_get_backend (); - GSettingsSchema *schema; keyboard->settings = g_settings_new ("org.gnome.desktop.peripherals.keyboard"); g_signal_connect (keyboard->settings, "changed", G_CALLBACK (settings_changed), keyboard); - /* We are cheating for now, we use g-s-d settings... Check if available */ - schema = g_settings_schema_source_lookup (g_settings_schema_source_get_default (), - GSD_KEYBOARD_SCHEMA, - TRUE); - if (schema) - { - keyboard->gsd_settings = g_settings_new_full (schema, NULL, NULL); - g_settings_schema_unref (schema); - g_signal_connect (keyboard->gsd_settings, "changed::remember-numlock-state", - G_CALLBACK (remember_numlock_state_changed), keyboard); - } - g_signal_connect (backend, "keymap-changed", G_CALLBACK (on_keymap_changed), keyboard); g_signal_connect (backend, "keymap-layout-group-changed", @@ -705,8 +570,6 @@ meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard) G_CALLBACK (on_kbd_a11y_mask_changed), keyboard); meta_wayland_keyboard_take_keymap (keyboard, meta_backend_get_keymap (backend)); - - maybe_restore_numlock_state (keyboard); } static void @@ -735,8 +598,6 @@ meta_wayland_keyboard_disable (MetaWaylandKeyboard *keyboard) wl_list_init (&keyboard->focus_resource_list); g_clear_object (&keyboard->settings); - if (keyboard->gsd_settings) - g_object_unref (keyboard->gsd_settings); } static guint @@ -802,8 +663,6 @@ meta_wayland_keyboard_handle_event (MetaWaylandKeyboard *keyboard, if (keyboard->mods_changed != 0) { - if (keyboard->mods_changed & XKB_STATE_MODS_LOCKED) - maybe_save_numlock_state (keyboard); notify_modifiers (keyboard); keyboard->mods_changed = 0; } diff --git a/src/wayland/meta-wayland-keyboard.h b/src/wayland/meta-wayland-keyboard.h index 20f309fff..1dd3b12ba 100644 --- a/src/wayland/meta-wayland-keyboard.h +++ b/src/wayland/meta-wayland-keyboard.h @@ -104,7 +104,6 @@ struct _MetaWaylandKeyboard MetaWaylandKeyboardGrab default_grab; GSettings *settings; - GSettings *gsd_settings; }; void meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard);