gimp but for windows: a wayland compositor
git clone https://github.com/m-col/wimp
Files | Refs | Readme

Commit 6cfd652362a213169a3e2b1dcc7fb54c58b882d9
Parent: 40faefb75809ef4560385c3fcdc1c48b8e0751d9
Author: mcol <mcol@posteo.net>
Date: 2021-03-01 19:30:20 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-03-01 19:30:20 +0000

add bind_marks option

wimp.conf Modified

@@ -54,6 +54,10 @@
 # Focus when moving the pointer over a window
 #wimptool set auto_focus on
 
+# Whether to automatically bind marks to keys if the key is vacant
+# This means instead of "mod+backtick 1" you can just do "mod+1"
+#wimptool set bind_marks on
+
 # Primary modifier be one of: shift, caps, ctrl, alt, mod2, mod3, logo, mod5
 #wimptool set mod logo
 

src/types.h Modified

@@ -59,6 +59,7 @@
     struct wl_list marks;
     bool mark_waiting;
     struct mark_indicator mark_indicator;
+    bool bind_marks;
 
     struct wlr_xdg_decoration_manager_v1 *decoration_manager;
     struct wl_listener decoration_listener;

src/ipc.c Modified

@@ -72,6 +72,7 @@
 	"set snap_box 47315c66",
 	"set mod Logo",
 	"set vt_switching on",
+	"set bind_marks on",
 	"bind Ctrl Escape terminate",
     };
     for (size_t i = 0; i < sizeof(defaults) / sizeof(defaults[0]); i++) {

src/input.c Modified

@@ -76,7 +76,7 @@
 	    xkb_state_key_get_syms(wlr_kb->xkb_state, keycode, &syms);
 	    mark = wl_container_of(wimp.marks.next, mark, link);
 	    if (mark->key) {
-		actually_go_to_mark(syms[0]);
+		actually_go_to_mark((void *)&syms[0]);
 	    } else {
 		actually_set_mark(syms[0]);
 	    }

src/config.c Modified

@@ -240,11 +240,20 @@
 	    wimp.reverse_scrolling = true;
     }
 
-    // e.g.: set_modifier logo
+    // mod <modifier>
     else if (!strcasecmp(s, "mod")) {
 	set_mod(message, response);
     }
 
+    // bind_marks [on|off]
+    else if (!strcasecmp(s, "bind_marks")) {
+	s = strtok(NULL, " \t\n\r");
+	if (!strcasecmp(s, "off"))
+	    wimp.bind_marks = false;
+	else if (!strcasecmp(s, "on"))
+	    wimp.bind_marks = true;
+    }
+
     // auto_focus [on|off]
     else if (!strcasecmp(s, "auto_focus")) {
 	s = strtok(NULL, " \t\n\r");

src/action.h Modified

@@ -21,7 +21,7 @@
 void set_mark(void *data);
 void actually_set_mark(const xkb_keysym_t sym);
 void go_to_mark(void *data);
-void actually_go_to_mark(const xkb_keysym_t sym);
+void actually_go_to_mark(void *data);
 void toggle_fullscreen(void *data);
 void halfimize(void *data);
 void maximize(void *data);

src/action.c Modified

@@ -289,6 +289,22 @@
 
     mark = wl_container_of(wimp.marks.next, mark, link);
     mark->key = sym;
+
+    if (wimp.bind_marks) {
+	struct binding *kb, *tmp;
+	wl_list_for_each_safe(kb, tmp, &wimp.key_bindings, link) {
+	    if (kb->key == sym && kb->mods == 0) {
+		return;
+	    }
+	}
+	kb = calloc(1, sizeof(struct binding));
+	kb->mods = 0;
+	kb->key = sym;
+	kb->data = calloc(1, sizeof(xkb_keysym_t));
+	kb->action = &actually_go_to_mark;
+	*(xkb_keysym_t *)(kb->data) = sym;
+	wl_list_insert(&wimp.key_bindings, &kb->link);
+    }
 }
 
 
@@ -298,7 +314,8 @@
 }
 
 
-void actually_go_to_mark(const xkb_keysym_t sym) {
+void actually_go_to_mark(void *data) {
+    const xkb_keysym_t sym = *(xkb_keysym_t *)data;
     struct mark *mark;
 
     if (sym == XKB_KEY_Escape) {