From 49a73befdbf5b2ece788a37e98c8e6a5a23274ef Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 20 Jul 2021 19:54:57 +0100 Subject: [PATCH] action: add 'MoveToEdge' Currently only moves view to edges of outputs Example keybind: left --- docs/rc.xml | 5 +++++ src/action.c | 2 ++ src/config/rcxml.c | 2 ++ src/view.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/docs/rc.xml b/docs/rc.xml index dbe834d4..0d61c7f4 100644 --- a/docs/rc.xml +++ b/docs/rc.xml @@ -32,6 +32,11 @@ bemenu-run + + left + right + up + down diff --git a/src/action.c b/src/action.c index a1cef98e..75e7623f 100644 --- a/src/action.c +++ b/src/action.c @@ -39,6 +39,8 @@ action(struct server *server, const char *action, const char *command) free(cmd.buf); } else if (!strcasecmp(action, "Exit")) { wl_display_terminate(server->wl_display); + } else if (!strcasecmp(action, "MoveToEdge")) { + view_move_to_edge(topmost_mapped_view(server), command); } else if (!strcasecmp(action, "NextWindow")) { server->cycle_view = desktop_cycle_view(server, server->cycle_view); diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 7c354677..dd92f702 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -52,6 +52,8 @@ fill_keybind(char *nodename, char *content) current_keybind->action = strdup(content); } else if (!strcmp(nodename, "command.action")) { current_keybind->command = strdup(content); + } else if (!strcmp(nodename, "direction.action")) { + current_keybind->command = strdup(content); } else if (!strcmp(nodename, "menu.action")) { current_keybind->command = strdup(content); } diff --git a/src/view.c b/src/view.c index 94e50636..075cd978 100644 --- a/src/view.c +++ b/src/view.c @@ -1,4 +1,5 @@ #include +#include #include "labwc.h" #include "ssd.h" @@ -130,3 +131,50 @@ view_for_each_popup_surface(struct view *view, wlr_surface_iterator_func_t itera view->impl->for_each_popup_surface(view, iterator, data); } +static struct border +view_border(struct view *view) +{ + struct border border = { + .left = view->margin.left - view->padding.left, + .top = view->margin.top - view->padding.top, + .right = view->margin.right + view->padding.right, + .bottom = view->margin.bottom + view->padding.bottom, + }; + return border; +} + +#define GAP (3) +void +view_move_to_edge(struct view *view, char *direction) +{ + if (!view) { + wlr_log(WLR_ERROR, "no view"); + return; + } + struct output *output = view_output(view); + struct border border = view_border(view); + struct wlr_box usable; + memcpy(&usable, &output->usable_area, sizeof(struct wlr_box)); + + double ox = 0, oy = 0; + wlr_output_layout_output_coords(view->server->output_layout, + output->wlr_output, &ox, &oy); + usable.x -= ox; + usable.y -= oy; + + int x, y; + if (!strcasecmp(direction, "left")) { + x = usable.x + border.left + GAP; + y = view->y; + } else if (!strcasecmp(direction, "up")) { + x = view->x; + y = usable.y + border.top + GAP; + } else if (!strcasecmp(direction, "right")) { + x = usable.x + usable.width - view->w - border.right - GAP; + y = view->y; + } else if (!strcasecmp(direction, "down")) { + x = view->x; + y = usable.y + usable.height - view->h - border.bottom - GAP; + } + view_move(view, x, y); +} -- 2.52.0