summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
authorMaarten van Gompel <proycon@anaproy.nl>2021-08-22 23:18:47 +0200
committerJohn Sullivan <jsullivan@csumb.edu>2021-10-19 23:12:01 -0700
commitd7030dbc6e0ab69ccece8b00579b953b91831c62 (patch)
treecd206a51957dc3d098398f98962f3a13d20aea93 /main.c
parent68962909c083c995b4fa44106a34429fc225d29b (diff)
downloadsuggpicker-d7030dbc6e0ab69ccece8b00579b953b91831c62.tar.gz
Added a compose button, copy type; added compose layouts and further layout updates
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/main.c b/main.c
index f37ea5c..ef3b217 100644
--- a/main.c
+++ b/main.c
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <wchar.h>
 #include <sys/mman.h>
 #include <wayland-client.h>
 
@@ -46,6 +47,7 @@ static uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
 /* application state */
 static bool run_display = true;
 static int cur_x = -1, cur_y = -1;
+static int compose = 0;
 
 /* event handler prototypes */
 static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
@@ -92,6 +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);
 
 /* event handlers */
 static const struct wl_pointer_listener pointer_listener = {
@@ -273,10 +276,27 @@ layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
 	run_display = false;
 }
 
+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);
+    size_t keymap_size = strlen(keymap_str) + 1;
+	int keymap_fd = os_create_anonymous_file(keymap_size);
+	if (keymap_fd < 0) {
+		die("could not create keymap fd\n");
+	}
+	void *ptr =
+	  mmap(NULL, keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, keymap_fd, 0);
+	if (ptr == (void *)-1) {
+		die("could not map keymap data\n");
+	}
+	strcpy(ptr, keymap_str);
+	zwp_virtual_keyboard_v1_keymap(
+	  keyboard.vkbd, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, keymap_size);
+}
+
 int
 main(int argc, char **argv) {
 	uint8_t i;
-	int keymap_fd = os_create_anonymous_file(keymap_size);
 
 	/* connect to compositor */
 	display = wl_display_connect(NULL);
@@ -307,17 +327,7 @@ main(int argc, char **argv) {
 	  zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(vkbd_mgr, seat);
 
 	/* upload keymap */
-	if (keymap_fd < 0) {
-		die("could not create keymap fd\n");
-	}
-	void *ptr =
-	  mmap(NULL, keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, keymap_fd, 0);
-	if (ptr == (void *)-1) {
-		die("could not map keymap data\n");
-	}
-	strcpy(ptr, keymap_str);
-	zwp_virtual_keyboard_v1_keymap(
-	  keyboard.vkbd, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, keymap_size);
+    create_and_upload_keymap(0,0);
 
 	/* assign kbd state */
 	keyboard.surf = &draw_surf;