]> git.mdlowis.com Git - proto/labwc.git/commitdiff
action: add 'MoveToEdge'
authorJohan Malm <jgm323@gmail.com>
Tue, 20 Jul 2021 18:54:57 +0000 (19:54 +0100)
committerJohan Malm <jgm323@gmail.com>
Tue, 20 Jul 2021 18:54:57 +0000 (19:54 +0100)
Currently only moves view to edges of outputs

Example keybind:

<keybind key="A-Left">
  <action name="MoveToEdge">
    <direction>left</direction>
  </action>
</keybind>

docs/rc.xml
src/action.c
src/config/rcxml.c
src/view.c

index dbe834d43f89d9184023d67de061f25f4e2bd015..0d61c7f48eab7cc88617fa90d03b907c83e55354 100644 (file)
     <keybind key="A-F3"><action name="Execute"><command>bemenu-run</command></action></keybind>
     <keybind key="A-F4"><action name="Close" /></keybind>
     <keybind key="W-a"><action name="ToggleMaximize" /></keybind>
+
+    <keybind key="A-Left"><action name="MoveToEdge"><direction>left</direction></action></keybind>
+    <keybind key="A-Right"><action name="MoveToEdge"><direction>right</direction></action></keybind>
+    <keybind key="A-Up"><action name="MoveToEdge"><direction>up</direction></action></keybind>
+    <keybind key="A-Down"><action name="MoveToEdge"><direction>down</direction></action></keybind>
   </keyboard>
 
 </labwc_config>
index a1cef98e0ccfdfa3ea7eb425f345a1bb4dba3613..75e7623f427a7516356e131053daf0ad73b090ef 100644 (file)
@@ -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);
index 7c3546771b3e6468aae60455da577d9791bd36e3..dd92f702973e1689120d6005dc2bc2bc3cfc2fad 100644 (file)
@@ -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);
        }
index 94e5063639bc6167fe211df6ff6d1c9d72049847..075cd978cd005fe32ad0541e37257ef5716d815d 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <strings.h>
 #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);
+}