Commit 3a10d94a2a266bd90ad27f8e29506f26735aabec Parent: 3e7f6d357deec527e53fd11a8fbbabe21eb9f696 Author: mcol <mcol@posteo.net> Date: 2021-01-24 16:11:27 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-01-24 16:11:36 +0000 Make pan_desk configurable by keybindings and percentages
src/types.h Modified
@@ -137,6 +137,7 @@ struct motion { double dx; double dy; + bool is_percentage; }; enum mouse_keys {
src/cursor.c Modified
@@ -116,6 +116,7 @@ struct motion motion = { .dx = dx, .dy = dy, + .is_percentage = false, }; server->on_mouse_motion(server, &motion); } @@ -177,11 +178,12 @@ struct motion motion = { .dx = 0, .dy = 0, + .is_percentage = false, }; if (event->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { - motion.dy = server->reverse_scrolling ? event->delta : - event->delta; + motion.dy = server->reverse_scrolling ? - event->delta : event->delta; } else { - motion.dx = server->reverse_scrolling ? event->delta : - event->delta; + motion.dx = server->reverse_scrolling ? - event->delta : event->delta; }; server->on_mouse_scroll(server, &motion); }
src/config.c Modified
@@ -70,13 +70,13 @@ } -static void dir_handler(struct binding *kb, const char *data) { +static void dir_handler(struct binding *kb, char *data) { kb->data = calloc(1, sizeof(enum direction)); *(enum direction *)(kb->data) = get(dirs, data); } -static void str_handler(struct binding *kb, const char *data) { +static void str_handler(struct binding *kb, char *data) { if (is_number(data)) { kb->data = calloc(1, sizeof(double)); *(double *)(kb->data) = strtod(data, NULL); @@ -87,10 +87,39 @@ } +static void motion_handler(struct binding *kb, char *data) { + kb->data = calloc(1, sizeof(struct motion)); + char *s; + if (!data) + goto fail; + + s = strtok(data, " \t\n\r"); + if (!is_number(s) || !data) + goto fail; + int x = atoi(s); + + s = strtok(NULL, " \t\n\r"); + if (!is_number(s)) + goto fail; + int y = atoi(s); + + struct motion motion = { + .dx = x, + .dy = y, + .is_percentage = true, + }; + *(struct motion *)(kb->data) = motion; + return; + +fail: + free(kb->data); +} + + static struct { const char *name; const action action; - void (*data_handler)(struct binding *kb, const char *data); + void (*data_handler)(struct binding *kb, char *data); } action_map[] = { { "shutdown", &shutdown, NULL }, { "exec", &exec_command, &str_handler }, @@ -98,7 +127,8 @@ { "focus", &focus_in_direction, &dir_handler }, { "next_desk", &next_desk, NULL }, { "prev_desk", &prev_desk, NULL }, - { "pan_desk", &pan_desk, NULL }, + { "pan_desk", &pan_desk, &motion_handler }, + { "pan_desk_mouse", &pan_desk, NULL }, { "reset_zoom", &reset_zoom, NULL }, { "zoom", &zoom, &str_handler }, { "zoom_mouse", &zoom_mouse, NULL }, @@ -112,7 +142,7 @@ static const int num_actions = sizeof(action_map) / sizeof(action_map[0]); -static bool assign_action(const char *name, const char *data, struct binding *kb) { +static bool assign_action(const char *name, char *data, struct binding *kb) { kb->action = NULL; kb->data = NULL;
src/action.c Modified
@@ -108,10 +108,16 @@ struct motion motion = *(struct motion*)data; double dx = motion.dx; double dy = motion.dy; + if (motion.is_percentage) { + struct wlr_box *extents = + wlr_output_layout_get_box(server->output_layout, NULL); + dx = extents->width * (dx / 100); + dy = extents->height * (dy / 100); + } struct view *view; wl_list_for_each(view, &desk->views, link) { - view->x += dx; - view->y += dy; + view->x -= dx; + view->y -= dy; } desk->panned_x += dx; desk->panned_y += dy;
readme.rst Modified
@@ -18,6 +18,5 @@ - fix issue where Shift-using key bindings require pre-shifted key in config - pan desk when focussing window in direction that isn't in view - xwayland - - functions to shift desk view - pinch gestures for desk zooming - draw rect with mouse when zoomed out to set new view
deskwm.conf Modified
@@ -58,6 +58,12 @@ bind o zoom -15 bind r reset_zoom +# These pan the desk using the given percentage changes in x and y +bind s pan_desk 0 40 +bind w pan_desk 0 -40 +bind a pan_desk -40 0 +bind d pan_desk 40 0 + # The line after 'exec' is executed by /bin/sh bind Return exec gnome-terminal @@ -70,7 +76,7 @@ bind grave go_to_mark # Possible mouse bindings: motion, scroll (+ additional modifiers) -bind scroll pan_desk +bind scroll pan_desk_mouse bind Shift scroll zoom_mouse # Scroll direction. Can be one of: natural, reverse