summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--keyboard.h14
-rw-r--r--main.c10
2 files changed, 18 insertions, 6 deletions
diff --git a/keyboard.h b/keyboard.h
index 79e4957..2e037d9 100644
--- a/keyboard.h
+++ b/keyboard.h
@@ -57,6 +57,7 @@ struct key {
 struct layout {
 	struct key *keys;
 	uint32_t keyheight; //absolute height (pixels)
+	const char * keymap_name;
 };
 
 struct kbd {
@@ -166,6 +167,9 @@ kbd_unpress_key(struct kbd *kb, uint32_t time) {
 
 		if (compose >= 2) {
 			compose = 0;
+			if ((!kb->prevlayout) || (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
+				create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
+			}
 			kb->layout = kb->prevlayout;
 			kbd_draw_layout(kb);
 		}
@@ -191,6 +195,9 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
 				if (compose) {
 					fprintf(stderr,"showing compose %d\n", compose);
 				}
+				if ((!kb->prevlayout) || (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
+					create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
+				}
 				kb->prevlayout = kb->layout;
 				kb->layout = k->layout;
 				kbd_draw_layout(kb);
@@ -224,12 +231,17 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
 		break;
 	case Layout:
 		kb->layout = k->layout;
+		if ((!kb->prevlayout) || (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
+			fprintf(stderr, "Switching to keymap %s\n", kb->layout->keymap_name);
+			create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
+		}
+		kb->prevlayout = kb->layout;
 		kbd_draw_layout(kb);
 	case Copy:
 		kb->last_press = k;
 		kbd_draw_key(kb, k, true);
 		fprintf(stderr,"pressing copy key\n");
-		create_and_upload_keymap(k->code, k->code_mod);
+		create_and_upload_keymap(kb->layout->keymap_name, k->code, k->code_mod);
 		zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
 		zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, //COMP key
 									WL_KEYBOARD_KEY_STATE_PRESSED);
diff --git a/main.c b/main.c
index ef3b217..982f0e0 100644
--- a/main.c
+++ b/main.c
@@ -17,7 +17,7 @@
 /* lazy die macro */
 #define die(...)                                                               \
 	fprintf(stderr, __VA_ARGS__);                                                \
-	exit(0)
+	exit(1)
 
 /* client state */
 static const char *namespace = "wlroots";
@@ -94,7 +94,7 @@ static void layer_surface_configure(void *data,
                                     uint32_t serial, uint32_t w, uint32_t h);
 static void layer_surface_closed(void *data,
                                  struct zwlr_layer_surface_v1 *surface);
-static void create_and_upload_keymap(uint32_t comp_unichr, uint32_t comp_shift_unichr);
+static void create_and_upload_keymap(const char * name, uint32_t comp_unichr, uint32_t comp_shift_unichr);
 
 /* event handlers */
 static const struct wl_pointer_listener pointer_listener = {
@@ -277,8 +277,8 @@ layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
 }
 
 void
-create_and_upload_keymap(uint32_t comp_unichr, uint32_t comp_shift_unichr) {
-    const char * keymap_str = get_keymap(comp_unichr, comp_shift_unichr);
+create_and_upload_keymap(const char * name, uint32_t comp_unichr, uint32_t comp_shift_unichr) {
+    const char * keymap_str = get_keymap(name, comp_unichr, comp_shift_unichr);
     size_t keymap_size = strlen(keymap_str) + 1;
 	int keymap_fd = os_create_anonymous_file(keymap_size);
 	if (keymap_fd < 0) {
@@ -327,7 +327,7 @@ main(int argc, char **argv) {
 	  zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(vkbd_mgr, seat);
 
 	/* upload keymap */
-    create_and_upload_keymap(0,0);
+    create_and_upload_keymap(layouts[DefaultLayout].keymap_name, 0,0);
 
 	/* assign kbd state */
 	keyboard.surf = &draw_surf;