Shade and Unshade actions

This commit is contained in:
Keith Bowes 2022-02-25 16:28:59 -05:00
parent 0769addabd
commit 8403f759c4
8 changed files with 90 additions and 57 deletions

View file

@ -26,6 +26,12 @@
<keybind key="W-S-M">
<action name="ToggleMaximize"/>
</keybind>
<keybind key="W-s">
<action name="Shade"/>
</keybind>
<keybind key="W-S-S">
<action name="Unshade"/>
</keybind>
<!-- Keybindings for window switching -->
<keybind key="A-Tab">
<action name="NextWindow">

View file

@ -44,7 +44,7 @@ struct wb_view {
struct wl_listener surface_commit;
bool mapped;
int width, height, x, y;
struct wlr_box current_position;
struct wlr_box previous_position;
};

View file

@ -103,6 +103,10 @@ static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt
key_bind->action = ACTION_TOGGLE_MAXIMIZE;
else if (strcmp(action, "Iconify") == 0)
key_bind->action = ACTION_ICONIFY;
else if (strcmp(action, "Shade") == 0)
key_bind->action = ACTION_SHADE;
else if (strcmp(action, "Unshade") == 0)
key_bind->action = ACTION_UNSHADE;
else if (strcmp(action, "Exit") == 0)
key_bind->action = ACTION_EXIT;
else if (strcmp(action, "Reconfigure") == 0)

View file

@ -12,7 +12,9 @@ enum action_type {
ACTION_NEXT_WINDOW,
ACTION_PREVIOUS_WINDOW,
ACTION_RECONFIGURE,
ACTION_SHADE,
ACTION_TOGGLE_MAXIMIZE,
ACTION_UNSHADE,
};
struct wb_config {

View file

@ -4,8 +4,8 @@
static void process_cursor_move(struct wb_server *server) {
/* Move the grabbed view to the new position. */
server->grabbed_view->x = server->cursor->cursor->x - server->grab_x;
server->grabbed_view->y = server->cursor->cursor->y - server->grab_y;
server->grabbed_view->current_position.x = server->cursor->cursor->x - server->grab_x;
server->grabbed_view->current_position.y = server->cursor->cursor->y - server->grab_y;
}
static void process_cursor_resize(struct wb_server *server) {
@ -42,8 +42,8 @@ static void process_cursor_resize(struct wb_server *server) {
struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
view->x = new_left - geo_box.x;
view->y = new_top - geo_box.y;
view->current_position.x = new_left - geo_box.x;
view->current_position.y = new_top - geo_box.y;
int new_width = new_right - new_left;
int new_height = new_bottom - new_top;

View file

@ -32,7 +32,7 @@ static void render_surface(struct wlr_surface *surface,
double ox = 0, oy = 0;
wlr_output_layout_output_coords(
view->server->output_layout, output, &ox, &oy);
ox += view->x + sx, oy += view->y + sy;
ox += view->current_position.x + sx, oy += view->current_position.y + sy;
/* We also have to apply the scale factor for HiDPI outputs. This is only
* part of the puzzle, Waybox does not fully support HiDPI. */

View file

@ -11,10 +11,10 @@ static void deiconify_view(struct wb_view *view) {
}
}
static bool cycle_views(struct wb_server *server) {
static void cycle_views(struct wb_server *server) {
/* Cycle to the next view */
if (wl_list_length(&server->views) < 1) {
return false;
return;
}
struct wb_view *current_view = wl_container_of(
server->views.prev, current_view, link);
@ -23,13 +23,12 @@ static bool cycle_views(struct wb_server *server) {
/* Move the current view to the beginning of the list */
wl_list_remove(&current_view->link);
wl_list_insert(&server->views, &current_view->link);
return true;
}
static bool cycle_views_reverse(struct wb_server *server) {
static void cycle_views_reverse(struct wb_server *server) {
/* Cycle to the previous view */
if (wl_list_length(&server->views) < 1) {
return false;
return;
}
struct wb_view *current_view = wl_container_of(
server->views.next, current_view, link);
@ -40,7 +39,6 @@ static bool cycle_views_reverse(struct wb_server *server) {
/* Move the current view to after the previous view in the list */
wl_list_remove(&current_view->link);
wl_list_insert(server->views.prev, &current_view->link);
return true;
}
static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32_t modifiers) {
@ -76,9 +74,11 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
switch (key_binding->action)
{
case ACTION_NEXT_WINDOW:
return cycle_views(server);
cycle_views(server);
break;
case ACTION_PREVIOUS_WINDOW:
return cycle_views_reverse(server);
cycle_views_reverse(server);
break;
case ACTION_CLOSE:
{
struct wb_view *current_view = wl_container_of(
@ -89,19 +89,20 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
#else
wlr_xdg_toplevel_send_close(current_view->xdg_surface);
#endif
return true;
break;
}
case ACTION_EXECUTE:
if (fork() == 0) {
execl("/bin/sh", "/bin/sh", "-c", key_binding->cmd, (char *) NULL);
}
return true;
break;
case ACTION_TOGGLE_MAXIMIZE:
{
struct wb_view *view = wl_container_of(server->views.next, view, link);
if (wlr_surface_is_xdg_surface(view->xdg_toplevel->base->surface))
wl_signal_emit(&view->xdg_toplevel->events.request_maximize, view->xdg_toplevel->base);
return true;
break;
}
case ACTION_ICONIFY:
{
struct wb_view *view = wl_container_of(server->views.next, view, link);
@ -112,19 +113,45 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
struct wb_view *previous_view = wl_container_of(server->views.prev, previous_view, link);
focus_view(previous_view, previous_view->xdg_toplevel->base->surface);
}
return true;
break;
}
case ACTION_SHADE:
{
struct wb_view *view = wl_container_of(server->views.next, view, link);
if (wlr_surface_is_xdg_surface(view->xdg_toplevel->base->surface))
{
view->previous_position = view->current_position;
wlr_xdg_toplevel_set_size(view->xdg_toplevel->base,
view->current_position.width, view->decoration_height);
}
break;
}
case ACTION_UNSHADE:
{
struct wb_view *view = wl_container_of(server->views.next, view, link);
if (wlr_surface_is_xdg_surface(view->xdg_toplevel->base->surface))
{
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel,
view->previous_position.width, view->previous_position.height);
#else
wlr_xdg_toplevel_set_size(view->xdg_surface,
view->previous_position.width, view->previous_position.height);
#endif
}
break;
}
case ACTION_RECONFIGURE:
deinit_config(server->config);
init_config(server);
return true;
break;
case ACTION_EXIT:
wl_display_terminate(server->wl_display);
return true;
break;
default:
continue;
}
return true;
}
}
return false;

View file

@ -59,11 +59,11 @@ static void xdg_surface_commit(struct wl_listener *listener, void *data) {
struct wlr_box geo_box = {0};
wlr_xdg_surface_get_geometry(xdg_surface, &geo_box);
if (geo_box.x < 0 && view->x < 1)
view->x += -geo_box.x;
if (geo_box.y < 0 && view->y < 1) {
if (geo_box.x < 0 && view->current_position.x < 1)
view->current_position.x += -geo_box.x;
if (geo_box.y < 0 && view->current_position.y < 1) {
view->decoration_height = -geo_box.y;
view->y += view->decoration_height;
view->current_position.y += view->decoration_height;
}
}
@ -76,10 +76,7 @@ static void xdg_surface_map(struct wl_listener *listener, void *data) {
struct wlr_box geo_box = {0};
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
view->height = geo_box.height;
view->width = geo_box.width;
view->x = geo_box.x;
view->y = geo_box.y;
view->current_position = geo_box;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel, geo_box.width, geo_box.height);
#else
@ -127,23 +124,23 @@ static void xdg_toplevel_request_maximize(struct wl_listener *listener, void *da
double closest_x, closest_y;
struct wlr_output *output = NULL;
wlr_output_layout_closest_point(view->server->output_layout, output, view->x + view->width / 2, view->y + view->height / 2, &closest_x, &closest_y);
wlr_output_layout_closest_point(view->server->output_layout, output,
view->current_position.x + view->current_position.width / 2,
view->current_position.y + view->current_position.height / 2,
&closest_x, &closest_y);
output = wlr_output_layout_output_at(view->server->output_layout, closest_x, closest_y);
bool is_maximized = surface->toplevel->current.maximized;
struct wlr_box usable_area = {0};
if (!is_maximized) {
wlr_output_effective_resolution(output, &usable_area.width, &usable_area.height);
view->previous_position.height = view->height;
view->previous_position.width = view->width;
view->previous_position.x = view->x;
view->previous_position.y = view->y;
view->x = 0;
view->y = 0 + view->decoration_height;
view->previous_position = view->current_position;
view->current_position.x = 0;
view->current_position.y = 0 + view->decoration_height;
} else {
usable_area = view->previous_position;
view->x = view->previous_position.x;
view->y = view->previous_position.y;
view->current_position.x = view->previous_position.x;
view->current_position.y = view->previous_position.y;
}
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(surface->toplevel, usable_area.width, usable_area.height);
@ -159,16 +156,11 @@ static void xdg_toplevel_request_minimize(struct wl_listener *listener, void *da
struct wb_view *view = wl_container_of(listener, view, request_minimize);
bool minimize_requested = surface->toplevel->requested.minimized;
if (minimize_requested) {
view->previous_position.height = view->height;
view->previous_position.width = view->width;
view->previous_position.x = view->x;
view->previous_position.y = view->y;
view->y = 0 - view->decoration_height * 2 - view->height;
view->previous_position.height = view->current_position.height;
view->current_position.y = 0 -
view->decoration_height * 2 - view->current_position.height;
} else {
view->height = view->previous_position.height;
view->width = view->previous_position.width;
view->x = view->previous_position.x;
view->y = view->previous_position.y;
view->current_position = view->previous_position;
}
}
@ -188,20 +180,20 @@ static void begin_interactive(struct wb_view *view,
server->cursor->cursor_mode = mode;
if (mode == WB_CURSOR_MOVE) {
server->grab_x = server->cursor->cursor->x - view->x;
server->grab_y = server->cursor->cursor->y - view->y;
server->grab_x = server->cursor->cursor->x - view->current_position.x;
server->grab_y = server->cursor->cursor->y - view->current_position.y;
} else if (mode == WB_CURSOR_RESIZE) {
struct wlr_box geo_box;
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
double border_x = (view->x + geo_box.x) + ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0);
double border_y = (view->y + geo_box.y) + ((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0);
double border_x = (view->current_position.x + geo_box.x) + ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0);
double border_y = (view->current_position.y + geo_box.y) + ((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0);
server->grab_x = server->cursor->cursor->x - border_x;
server->grab_y = server->cursor->cursor->y - border_y;
server->grab_geo_box = geo_box;
server->grab_geo_box.x += view->x;
server->grab_geo_box.y += view->y;
server->grab_geo_box.x += view->current_position.x;
server->grab_geo_box.y += view->current_position.y;
server->resize_edges = edges;
}
@ -231,7 +223,9 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
struct wb_view *view = wl_container_of(listener, view, new_popup);
struct wlr_output_layout *output_layout = view->server->output_layout;
struct wlr_output *wlr_output = wlr_output_layout_output_at(output_layout, view->x + popup->geometry.x, view->y + popup->geometry.y);
struct wlr_output *wlr_output = wlr_output_layout_output_at(output_layout,
view->current_position.x + popup->geometry.x,
view->current_position.y + popup->geometry.y);
struct wlr_box output_box;
#if WLR_CHECK_VERSION(0, 16, 0)
wlr_output_layout_get_box(output_layout, wlr_output, &output_box);
@ -239,8 +233,8 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
output_box = (*wlr_output_layout_get_box(output_layout, wlr_output));
#endif
struct wlr_box output_toplevel_box = {
.x = output_box.x - view->x,
.y = output_box.y - view->y,
.x = output_box.x - view->current_position.x,
.y = output_box.y - view->current_position.y,
.width = output_box.width,
.height = output_box.height,
};
@ -309,8 +303,8 @@ bool view_at(struct wb_view *view,
if (view->xdg_toplevel->base->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
return false;
double view_sx = lx - view->x;
double view_sy = ly - view->y;
double view_sx = lx - view->current_position.x;
double view_sy = ly - view->current_position.y;
double _sx, _sy;
struct wlr_surface *_surface = NULL;