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

Commit 2fcc7729953ee50d8d1769b38b8a589d80e65e09
Parent: 5517e33716b4e0a49c0f7a7c0b800f89538dfe90
Author: mcol <mcol@posteo.net>
Date: 2021-01-28 11:54:00 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-01-28 11:54:00 +0000

add drag mouse handlers for better moving

wimp.conf Modified

@@ -80,10 +80,10 @@
 bind		m		set_mark
 bind		grave		go_to_mark
 
-# Possible mouse bindings: motion, scroll (+ additional modifiers)
+# Possible mouse bindings: motion, scroll, drag{1,2,3} (+ additional modifiers)
 bind		scroll		pan_desk_mouse
 bind	Shift	scroll		zoom_mouse
-bind		motion		move_window
+bind		drag1		move_window
 
 # Scroll direction. Can be one of: natural, reverse
 #scroll_direction natural

src/types.h Modified

@@ -78,8 +78,13 @@
     enum wlr_keyboard_modifier mod;
     struct wl_list key_bindings;
     struct wl_list mouse_bindings;
+
     action on_mouse_motion;
     action on_mouse_scroll;
+    action on_drag1;
+    action on_drag2;
+    action on_drag3;
+
     bool reverse_scrolling;
     enum cursor_mode cursor_mode;
     struct view *grabbed_view;
@@ -165,6 +170,9 @@
 enum mouse_keys {
     MOTION = 1,
     SCROLL = 2,
+    DRAG1 = 3,
+    DRAG2 = 4,
+    DRAG3 = 5,
 };
 
 struct mark {

src/main.c Modified

@@ -27,6 +27,9 @@
     .mark_waiting = false,
     .on_mouse_motion = NULL,
     .on_mouse_scroll = NULL,
+    .on_drag1 = NULL,
+    .on_drag2 = NULL,
+    .on_drag3 = NULL,
     .can_steal_focus = true,
     .desk_count = 0,
     .mark_indicator.box.width = 25,

src/keyboard.c Modified

@@ -16,6 +16,7 @@
     );
 
     uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
+    bool handled;
     struct binding *kb;
     if ((modifiers & wimp.mod)) {
 	modifiers &= ~wimp.mod;
@@ -28,14 +29,25 @@
 		    case SCROLL:
 			wimp.on_mouse_scroll = kb->action;
 			break;
+		    case DRAG1:
+			wimp.on_drag1 = kb->action;
+			break;
+		    case DRAG2:
+			wimp.on_drag2 = kb->action;
+			break;
+		    case DRAG3:
+			wimp.on_drag3 = kb->action;
+			break;
 		}
 		wimp.cursor_mode = CURSOR_MOD;
-		return;
+		handled = true;
 	    }
 	}
     }
 
-    wimp.cursor_mode = CURSOR_PASSTHROUGH;
+    if (!handled){
+	wimp.cursor_mode = CURSOR_PASSTHROUGH;
+    }
 }
 
 

src/cursor.c Modified

@@ -1,4 +1,5 @@
 #include <inttypes.h>
+#include <linux/input-event-codes.h>
 #include <unistd.h>
 #include <wlr/types/wlr_cursor.h>
 #include <wlr/types/wlr_xcursor_manager.h>
@@ -150,7 +151,32 @@
     wlr_seat_pointer_notify_button(wimp.seat, event->time_msec, event->button, event->state);
 
     if (event->state == WLR_BUTTON_RELEASED) {
+	if (wimp.cursor_mode == CURSOR_MOD) {
+	    wimp.on_mouse_motion = NULL;
+	    struct binding *kb;
+	    wl_list_for_each(kb, &wimp.mouse_bindings, link) {
+		if (kb->key == MOTION) {
+		    wimp.on_mouse_motion = kb->action;
+		    break;
+		}
+	    }
+	}
 	wimp.cursor_mode = CURSOR_PASSTHROUGH;
+
+    } else if (wimp.cursor_mode == CURSOR_MOD) {
+	switch (event->button) {
+	    case BTN_LEFT:
+		wimp.on_mouse_motion = wimp.on_drag1;
+		break;
+	    case BTN_MIDDLE:
+		wimp.on_mouse_motion = wimp.on_drag2;
+		break;
+	    case BTN_RIGHT:
+		wimp.on_mouse_motion = wimp.on_drag3;
+		break;
+	}
+
+
     } else {
 	double sx, sy;
 	struct wlr_surface *surface;

src/config.c Modified

@@ -67,6 +67,9 @@
 static struct value_map mouse_keys[] = {
     { "motion", MOTION },
     { "scroll", SCROLL },
+    { "drag1", DRAG1 },
+    { "drag2", DRAG2 },
+    { "drag3", DRAG3 },
 };