diff --git a/include/absinthe-toplevel.h b/include/absinthe-toplevel.h index d7de85e..edb8810 100644 --- a/include/absinthe-toplevel.h +++ b/include/absinthe-toplevel.h @@ -2,7 +2,7 @@ struct absinthe_toplevel *absinthe_toplevel_at(struct absinthe_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); -void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel); void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y); void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t width, int32_t height); void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, const float color[4]); +void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel); diff --git a/include/types.h b/include/types.h index 540b93a..18474de 100644 --- a/include/types.h +++ b/include/types.h @@ -24,8 +24,14 @@ #define ABSINTHE_BORDER_WIDTH 1 +#define ABSINTHE_WINDOW_MIN_WIDTH 200 +#define ABSINTHE_WINDOW_MIN_HEIGHT 200 + static const float bordercolor[4] = {0.88, 0.18, 0.18, 1.0}; +#define MAX(a, b) a > b ? a : b +#define MIN(a, b) a < b ? a : b + enum absinthe_cursor_mode { ABSINTHE_CURSOR_PASSTHROUGH, ABSINTHE_CURSOR_MOVE, @@ -87,6 +93,7 @@ struct absinthe_server { struct absinthe_output { struct wl_list link; struct absinthe_server *server; + struct wlr_box geometry; struct wlr_output *wlr_output; struct wl_listener frame; struct wl_listener request_state; diff --git a/src/absinthe-toplevel.c b/src/absinthe-toplevel.c index de1713f..893cfc6 100644 --- a/src/absinthe-toplevel.c +++ b/src/absinthe-toplevel.c @@ -1,4 +1,5 @@ #include +#include #include "types.h" #include "xdg-toplevel.h" @@ -24,28 +25,6 @@ struct absinthe_toplevel *absinthe_toplevel_at(struct absinthe_server *server, d return tree->node.data; } -void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel) -{ - int bw = ABSINTHE_BORDER_WIDTH; - - if (toplevel->geometry.width - 2 * bw < 0 || toplevel->geometry.height - 2 * bw < 0) { - return; - } - - wlr_scene_node_set_position(&toplevel->scene_tree->node, toplevel->geometry.x, toplevel->geometry.y); - wlr_scene_node_set_position(&toplevel->scene_surface->node, bw, bw); - - wlr_scene_rect_set_size(toplevel->border[0], toplevel->geometry.width - 2 * bw, bw); - wlr_scene_rect_set_size(toplevel->border[1], toplevel->geometry.width - 2 * bw, bw); - wlr_scene_rect_set_size(toplevel->border[2], bw, toplevel->geometry.height); - wlr_scene_rect_set_size(toplevel->border[3], bw, toplevel->geometry.height); - - wlr_scene_node_set_position(&toplevel->border[0]->node, bw, 0); - wlr_scene_node_set_position(&toplevel->border[1]->node, bw, toplevel->geometry.height - bw); - wlr_scene_node_set_position(&toplevel->border[2]->node, 0, 0); - wlr_scene_node_set_position(&toplevel->border[3]->node, toplevel->geometry.width - bw, 0); -} - void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y) { wlr_scene_node_set_position(&toplevel->scene_tree->node, x, y); @@ -55,9 +34,8 @@ void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t widt { int bw = ABSINTHE_BORDER_WIDTH; - if (width - 2 * bw < 0 || height - 2 * bw < 0) { + if (width < 0 || height < 0) return; - } toplevel->geometry.width = width; toplevel->geometry.height = height; @@ -72,3 +50,24 @@ void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, cons wlr_scene_rect_set_color(toplevel->border[i], color); } } + +void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel) +{ + int bw = ABSINTHE_BORDER_WIDTH; + + if (toplevel->geometry.width - 2 * bw < 0 || toplevel->geometry.height - 2 * bw < 0) + return; + + wlr_scene_node_set_position(&toplevel->scene_tree->node, toplevel->geometry.x, toplevel->geometry.y); + wlr_scene_node_set_position(&toplevel->scene_surface->node, bw, bw); + + wlr_scene_rect_set_size(toplevel->border[0], toplevel->geometry.width - 2 * bw, bw); + wlr_scene_rect_set_size(toplevel->border[1], toplevel->geometry.width - 2 * bw, bw); + wlr_scene_rect_set_size(toplevel->border[2], bw, toplevel->geometry.height); + wlr_scene_rect_set_size(toplevel->border[3], bw, toplevel->geometry.height); + + wlr_scene_node_set_position(&toplevel->border[0]->node, bw, 0); + wlr_scene_node_set_position(&toplevel->border[1]->node, bw, toplevel->geometry.height - bw); + wlr_scene_node_set_position(&toplevel->border[2]->node, 0, 0); + wlr_scene_node_set_position(&toplevel->border[3]->node, toplevel->geometry.width - bw, 0); +} diff --git a/src/cursor.c b/src/cursor.c index d06dc83..8adf095 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -13,7 +13,8 @@ void reset_cursor_mode(struct absinthe_server *server) static void process_cursor_move(struct absinthe_server *server) { struct absinthe_toplevel *toplevel = server->grabbed_toplevel; - if (!toplevel) return; + if (!toplevel) + return; uint32_t new_x, new_y; new_x = server->cursor->x - server->grab_x + server->grabbed_geometry.x; @@ -26,9 +27,11 @@ static void process_cursor_move(struct absinthe_server *server) { static void process_cursor_resize(struct absinthe_server *server) { struct absinthe_toplevel *toplevel = server->grabbed_toplevel; - if (toplevel->performing_resize == true) return; + if (toplevel->performing_resize == true) + return; - if (!toplevel) return; + if (!toplevel) + return; int bw = ABSINTHE_BORDER_WIDTH; @@ -41,9 +44,8 @@ static void process_cursor_resize(struct absinthe_server *server) { int32_t dx = server->cursor->x - server->grab_x; int32_t dy = server->cursor->y - server->grab_y; - if (dx == 0 && dy == 0) { + if (dx == 0 && dy == 0) return; - } switch (server->cursor_resize_corner) { case ABSINTHE_CURSOR_RESIZE_CORNER_TOP_LEFT: @@ -94,9 +96,10 @@ void process_cursor_motion(struct absinthe_server *server, uint32_t time) struct wlr_seat *seat = server->seat; struct wlr_surface *surface = NULL; struct absinthe_toplevel *toplevel = absinthe_toplevel_at(server, server->cursor->x, server->cursor->y, &surface, &sx, &sy); - if (!toplevel) { + + if (!toplevel) wlr_cursor_set_xcursor(server->cursor, server->cursor_mgr, "default"); - } + if (surface) { wlr_seat_pointer_notify_enter(seat, surface, sx, sy); wlr_seat_pointer_notify_motion(seat, time, sx, sy); diff --git a/src/focus.c b/src/focus.c index 7693f22..6dcfaab 100644 --- a/src/focus.c +++ b/src/focus.c @@ -4,18 +4,16 @@ void focus_toplevel(struct absinthe_toplevel *toplevel) { - if (!toplevel) { + if (!toplevel) return; - } struct absinthe_server *server = toplevel->server; struct wlr_seat *seat = server->seat; struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface; struct wlr_surface *surface = toplevel->xdg_toplevel->base->surface; - if (surface == prev_surface) { + if (surface == prev_surface) return; - } if (prev_surface) { struct wlr_xdg_toplevel *prev_toplevel = wlr_xdg_toplevel_try_from_wlr_surface(prev_surface); @@ -28,7 +26,6 @@ void focus_toplevel(struct absinthe_toplevel *toplevel) wl_list_insert(&server->toplevels, &toplevel->link); wlr_xdg_toplevel_set_activated(toplevel->xdg_toplevel, true); - if (keyboard) { + if (keyboard) wlr_seat_keyboard_notify_enter(seat, surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); - } } diff --git a/src/keyboard.c b/src/keyboard.c index af342c2..66fd0f0 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -20,15 +20,9 @@ static bool keyboard_handle_keybind(struct absinthe_server *server, xkb_keysym_t case XKB_KEY_Escape: wl_display_terminate(server->display); break; - case XKB_KEY_Q: - if (fork() == 0) { - execl("/bin/sh", "sh", "-c", "wofi --show drun", NULL); - } - break; case XKB_KEY_Return: - if (fork() == 0) { + if (fork() == 0) execl("/bin/sh", "sh", "-c", "alacritty", NULL); - } break; default: return false; diff --git a/src/output.c b/src/output.c index 3021bcd..fee4b7b 100644 --- a/src/output.c +++ b/src/output.c @@ -51,7 +51,9 @@ void output_layout_change(struct wl_listener *listener, void *data) wl_list_for_each(output, &server->outputs, link) { if (!output->wlr_output->enabled || !wlr_output_layout_get(server->output_layout, output->wlr_output)) continue; + wlr_output_layout_add_auto(server->output_layout, output->wlr_output); + wlr_output_layout_get_box(server->output_layout, output->wlr_output, &output->geometry); } wlr_output_manager_v1_set_configuration(server->output_mgr, config); diff --git a/src/seat.c b/src/seat.c index 45b9f67..4633087 100644 --- a/src/seat.c +++ b/src/seat.c @@ -9,9 +9,8 @@ void seat_request_cursor(struct wl_listener *listener, void *data) struct wlr_seat_pointer_request_set_cursor_event *event = data; struct wlr_seat_client *client = server->seat->pointer_state.focused_client; - if (client == event->seat_client) { + if (client == event->seat_client) wlr_cursor_set_surface(server->cursor, event->surface, event->hotspot_x, event->hotspot_y); - } } void seat_pointer_focus_change(struct wl_listener *listener, void *data) @@ -19,9 +18,8 @@ void seat_pointer_focus_change(struct wl_listener *listener, void *data) struct absinthe_server *server = wl_container_of(listener, server, pointer_focus_change); struct wlr_seat_pointer_focus_change_event *event = data; - if (!event->new_surface) { + if (!event->new_surface) wlr_cursor_set_xcursor(server->cursor, server->cursor_mgr, "default"); - } } void seat_request_set_selection(struct wl_listener *listener, void *data) diff --git a/src/server.c b/src/server.c index 9551a39..ea2fb36 100644 --- a/src/server.c +++ b/src/server.c @@ -61,10 +61,6 @@ void server_new_xdg_toplevel(struct wl_listener *listener, void *data) toplevel->scene_tree = wlr_scene_tree_create(&toplevel->server->scene->tree); toplevel->scene_tree->node.data = toplevel; toplevel->scene_surface = wlr_scene_xdg_surface_create(toplevel->scene_tree, xdg_toplevel->base); - toplevel->geometry.x = 0; - toplevel->geometry.y = 0; - toplevel->geometry.width = 100; - toplevel->geometry.height = 100; xdg_toplevel->base->data = toplevel; toplevel->map.notify = xdg_toplevel_map; diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 9859bf8..9421e85 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -8,9 +8,8 @@ void xdg_popup_commit(struct wl_listener *listener, void *data) { struct absinthe_popup *popup = wl_container_of(listener, popup, commit); - if (popup->xdg_popup->base->initial_commit) { + if (popup->xdg_popup->base->initial_commit) wlr_xdg_surface_schedule_configure(popup->xdg_popup->base); - } } void xdg_popup_destroy(struct wl_listener *listener, void *data) diff --git a/src/xdg-toplevel.c b/src/xdg-toplevel.c index c35f05d..da0de04 100644 --- a/src/xdg-toplevel.c +++ b/src/xdg-toplevel.c @@ -1,6 +1,7 @@ #include #include +#include #include "types.h" #include "xdg-decoration.h" @@ -11,13 +12,16 @@ void xdg_toplevel_commit(struct wl_listener *listener, void *data) struct absinthe_toplevel *toplevel = wl_container_of(listener, toplevel, commit); if (toplevel->xdg_toplevel->base->initial_commit) { - int bw = ABSINTHE_BORDER_WIDTH; + int32_t cw = toplevel->xdg_toplevel->current.min_width; + int32_t ch = toplevel->xdg_toplevel->current.min_height; - absinthe_toplevel_set_size(toplevel, toplevel->geometry.width - 2 * bw, toplevel->geometry.height - 2 * bw); + int32_t w = MAX(cw, ABSINTHE_WINDOW_MIN_WIDTH); + int32_t h = MAX(ch, ABSINTHE_WINDOW_MIN_HEIGHT); + + absinthe_toplevel_set_size(toplevel, w, h); - if (toplevel->decoration) { + if (toplevel->decoration) xdg_decoration_request_mode(&toplevel->decoration_request_mode, toplevel->decoration); - } } else { absinthe_toplevel_set_position(toplevel, toplevel->geometry.x, toplevel->geometry.y); absinthe_toplevel_update_borders_geometry(toplevel); @@ -34,11 +38,8 @@ void xdg_toplevel_map(struct wl_listener *listener, void *data) toplevel->border[i]->node.data = toplevel; } - int bw = ABSINTHE_BORDER_WIDTH; - - absinthe_toplevel_set_size(toplevel, toplevel->geometry.width - 2 * bw, toplevel->geometry.height - 2 * bw); - absinthe_toplevel_set_border_color(toplevel, bordercolor); + absinthe_toplevel_update_borders_geometry(toplevel); wl_list_insert(&toplevel->server->toplevels, &toplevel->link); } @@ -69,31 +70,27 @@ void xdg_toplevel_destroy(struct wl_listener *listener, void *data) void xdg_toplevel_request_move(struct wl_listener *listener, void *data) { struct absinthe_toplevel *toplevel = wl_container_of(listener, toplevel, request_maximize); - if (toplevel->xdg_toplevel->base->initialized) { + if (toplevel->xdg_toplevel->base->initialized) wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base); - } } void xdg_toplevel_request_resize(struct wl_listener *listener, void *data) { struct absinthe_toplevel *toplevel = wl_container_of(listener, toplevel, request_maximize); - if (toplevel->xdg_toplevel->base->initialized) { + if (toplevel->xdg_toplevel->base->initialized) wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base); - } } void xdg_toplevel_request_maximize(struct wl_listener *listener, void *data) { struct absinthe_toplevel *toplevel = wl_container_of(listener, toplevel, request_maximize); - if (toplevel->xdg_toplevel->base->initialized) { + if (toplevel->xdg_toplevel->base->initialized) wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base); - } } void xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data) { struct absinthe_toplevel *toplevel = wl_container_of(listener, toplevel, request_fullscreen); - if (toplevel->xdg_toplevel->base->initialized) { + if (toplevel->xdg_toplevel->base->initialized) wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base); - } }