Skip to content

Commit

Permalink
Fixes #45 and #47
Browse files Browse the repository at this point in the history
  • Loading branch information
zen-tools committed Jul 14, 2024
1 parent 8716187 commit ed128e2
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/xkb-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ typedef struct {
XklEngine *engine;

t_group_data *group_data;

t_xkb_settings *settings;

GHashTable *application_map;
Expand All @@ -55,9 +54,10 @@ typedef struct {
gint current_group;

XkbCallback callback;

gpointer callback_data;

guint config_changed_timeout_id;

XklConfigRec *config_rec;
} t_xkb_config;

Expand All @@ -67,9 +67,9 @@ void xkb_config_xkl_state_changed(XklEngine *engine,
XklEngineStateChange *change, gint group,
gboolean restore);

void xkb_config_xkl_config_changed(XklEngine *engine);
void xkb_config_xkl_config_changed(XklEngine *engine, t_xkb_config *config);

void xkb_config_xkl_new_device(XklEngine *engine, gpointer data);
void xkb_config_xkl_new_device(XklEngine *engine);

GdkFilterReturn handle_xevent(GdkXEvent *xev, GdkEvent *event);

Expand Down Expand Up @@ -143,7 +143,7 @@ gboolean xkb_config_initialize(t_xkb_settings *settings, XkbCallback callback,
G_CALLBACK(xkb_config_xkl_state_changed), NULL);

g_signal_connect(config->engine, "X-config-changed",
G_CALLBACK(xkb_config_xkl_config_changed), NULL);
G_CALLBACK(xkb_config_xkl_config_changed), config);

g_signal_connect(config->engine, "X-new-device",
G_CALLBACK(xkb_config_xkl_new_device), NULL);
Expand Down Expand Up @@ -591,12 +591,13 @@ void xkb_config_xkl_state_changed(XklEngine *engine,
}
}

void xkb_config_xkl_config_changed(XklEngine *engine) {
static gboolean xkb_keyboard_xkl_config_changed_timeout (gpointer user_data) {
t_xkb_config *config = user_data;
gchar *previous_active_group_name = strdup(xkb_config_get_group_name(-1));

kbd_config_free(config->settings->kbd_config);
config->settings->kbd_config = NULL;
xkb_config_update_settings(config->settings, engine);
xkb_config_update_settings(config->settings, config->engine);

// If group name for current window is mismatch, then it means previous
// group name is not exist in new configuration, let's reset it
Expand All @@ -615,9 +616,25 @@ void xkb_config_xkl_config_changed(XklEngine *engine) {
config->callback(xkb_config_get_current_group(), FALSE,
config->callback_data);
}

config->config_changed_timeout_id = 0;
return G_SOURCE_REMOVE;
}

void xkb_config_xkl_config_changed(XklEngine *engine, t_xkb_config *config) {
// libxklavier may send default Xorg settings first,
// which leads to losing the actual keyboard layout settings.
// To avoid this, we run the callback with a delay.
// If there was already one scheduled, then we drop it.

if (config->config_changed_timeout_id != 0)
g_source_remove(config->config_changed_timeout_id);

config->config_changed_timeout_id = g_timeout_add(
100, xkb_keyboard_xkl_config_changed_timeout, config);
}

void xkb_config_xkl_new_device(XklEngine *engine, gpointer data) {
void xkb_config_xkl_new_device(XklEngine *engine) {
if (!config->settings->never_modify_config)
xkl_config_rec_activate(config->config_rec, engine);
}
Expand Down

0 comments on commit ed128e2

Please sign in to comment.