implement Resize as an action

this requires action() to know the resize edges to use, so thread them through
This commit is contained in:
bi4k8 2021-12-01 02:38:53 +00:00 committed by Johan Malm
parent 8eab1e8132
commit 031ced85ef
5 changed files with 24 additions and 13 deletions

View file

@ -470,7 +470,8 @@ void server_init(struct server *server);
void server_start(struct server *server); void server_start(struct server *server);
void server_finish(struct server *server); void server_finish(struct server *server);
void action(struct server *server, const char *action, const char *command); void action(struct server *server, const char *action, const char *command,
uint32_t resize_edges);
/* update onscreen display 'alt-tab' texture */ /* update onscreen display 'alt-tab' texture */
void osd_update(struct server *server); void osd_update(struct server *server);

View file

@ -20,7 +20,7 @@ show_menu(struct server *server, const char *menu)
} }
void void
action(struct server *server, const char *action, const char *command) action(struct server *server, const char *action, const char *command, uint32_t resize_edges)
{ {
if (!action) if (!action)
return; return;
@ -77,6 +77,11 @@ action(struct server *server, const char *action, const char *command)
if (view) { if (view) {
interactive_begin(view, LAB_INPUT_STATE_MOVE, 0); interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
} }
} else if (!strcasecmp(action, "Resize")) {
struct view *view = desktop_view_at_cursor(server);
if (view) {
interactive_begin(view, LAB_INPUT_STATE_RESIZE, resize_edges);
}
} else { } else {
wlr_log(WLR_ERROR, "action (%s) not supported", action); wlr_log(WLR_ERROR, "action (%s) not supported", action);
} }

View file

@ -443,7 +443,7 @@ handle_cursor_button_with_meta_key(struct view *view, uint32_t button,
} }
static void static void
handle_release_mousebinding(struct server *server, uint32_t button, uint32_t modifiers, enum ssd_part_type view_area) handle_release_mousebinding(struct server *server, uint32_t button, uint32_t modifiers, enum ssd_part_type view_area, uint32_t resize_edges)
{ {
struct mousebind *mousebind; struct mousebind *mousebind;
wl_list_for_each_reverse(mousebind, &rc.mousebinds, link) { wl_list_for_each_reverse(mousebind, &rc.mousebinds, link) {
@ -453,12 +453,12 @@ handle_release_mousebinding(struct server *server, uint32_t button, uint32_t mod
if (mousebind->mouse_event if (mousebind->mouse_event
== MOUSE_ACTION_RELEASE) { == MOUSE_ACTION_RELEASE) {
action(server, mousebind->action, action(server, mousebind->action,
mousebind->command); mousebind->command, resize_edges);
} }
if (mousebind->pressed_in_context) { if (mousebind->pressed_in_context) {
mousebind->pressed_in_context = false; mousebind->pressed_in_context = false;
action(server, mousebind->action, action(server, mousebind->action,
mousebind->command); mousebind->command, resize_edges);
} }
} }
} }
@ -488,7 +488,7 @@ is_double_click(long double_click_speed, uint32_t button)
} }
static bool static bool
handle_press_mousebinding(struct server *server, uint32_t button, uint32_t modifiers, enum ssd_part_type view_area) handle_press_mousebinding(struct server *server, uint32_t button, uint32_t modifiers, enum ssd_part_type view_area, uint32_t resize_edges)
{ {
struct mousebind *mousebind; struct mousebind *mousebind;
bool double_click = is_double_click(rc.doubleclick_time, button); bool double_click = is_double_click(rc.doubleclick_time, button);
@ -502,7 +502,7 @@ handle_press_mousebinding(struct server *server, uint32_t button, uint32_t modif
== MOUSE_ACTION_PRESS) { == MOUSE_ACTION_PRESS) {
bound = true; bound = true;
action(server, mousebind->action, action(server, mousebind->action,
mousebind->command); mousebind->command, resize_edges);
} else if (mousebind->mouse_event } else if (mousebind->mouse_event
== MOUSE_ACTION_CLICK) { == MOUSE_ACTION_CLICK) {
bound = true; bound = true;
@ -512,7 +512,7 @@ handle_press_mousebinding(struct server *server, uint32_t button, uint32_t modif
== MOUSE_ACTION_DOUBLECLICK) { == MOUSE_ACTION_DOUBLECLICK) {
bound = true; bound = true;
action(server, mousebind->action, action(server, mousebind->action,
mousebind->command); mousebind->command, resize_edges);
} }
} }
} }
@ -590,7 +590,7 @@ cursor_button(struct wl_listener *listener, void *data)
/* Handle _press_ on root window */ /* Handle _press_ on root window */
if (!view) { if (!view) {
action(server, "ShowMenu", "root-menu"); action(server, "ShowMenu", "root-menu", 0);
return; return;
} }
@ -599,17 +599,22 @@ cursor_button(struct wl_listener *listener, void *data)
desktop_raise_view(view); desktop_raise_view(view);
damage_all_outputs(server); damage_all_outputs(server);
/* Resize if SSD resize edge is clicked */
resize_edges = ssd_resize_edges(view_area); resize_edges = ssd_resize_edges(view_area);
if (resize_edges) { if (resize_edges) {
interactive_begin(view, LAB_INPUT_STATE_RESIZE, resize_edges); interactive_begin(view, LAB_INPUT_STATE_RESIZE, resize_edges);
return; return;
} }
/* Determine closest resize edges in case action is Resize */
resize_edges |= server->seat.cursor->x < view->x + view->w / 2 ? WLR_EDGE_LEFT : WLR_EDGE_RIGHT;
resize_edges |= server->seat.cursor->y < view->y + view->h / 2 ? WLR_EDGE_TOP : WLR_EDGE_BOTTOM;
mousebindings: mousebindings:
if (event->state == WLR_BUTTON_RELEASED) { if (event->state == WLR_BUTTON_RELEASED) {
handle_release_mousebinding(server, event->button, modifiers, view_area); handle_release_mousebinding(server, event->button, modifiers, view_area, resize_edges);
} else if (event->state == WLR_BUTTON_PRESSED) { } else if (event->state == WLR_BUTTON_PRESSED) {
handle_press_mousebinding(server, event->button, modifiers, view_area); handle_press_mousebinding(server, event->button, modifiers, view_area, resize_edges);
} }
} }

View file

@ -65,7 +65,7 @@ handle_keybinding(struct server *server, uint32_t modifiers, xkb_keysym_t sym)
for (size_t i = 0; i < keybind->keysyms_len; i++) { for (size_t i = 0; i < keybind->keysyms_len; i++) {
if (xkb_keysym_to_lower(sym) == keybind->keysyms[i]) { if (xkb_keysym_to_lower(sym) == keybind->keysyms[i]) {
action(server, keybind->action, action(server, keybind->action,
keybind->command); keybind->command, 0);
return true; return true;
} }
} }

View file

@ -416,7 +416,7 @@ menu_action_selected(struct server *server, struct menu *menu)
struct menuitem *menuitem; struct menuitem *menuitem;
wl_list_for_each (menuitem, &menu->menuitems, link) { wl_list_for_each (menuitem, &menu->menuitems, link) {
if (menuitem->selected && !menuitem->submenu) { if (menuitem->selected && !menuitem->submenu) {
action(server, menuitem->action, menuitem->command); action(server, menuitem->action, menuitem->command, 0);
break; break;
} }
if (menuitem->submenu) { if (menuitem->submenu) {