diff --git a/kiwmi/desktop/desktop.c b/kiwmi/desktop/desktop.c index 8edc491..ce9b144 100644 --- a/kiwmi/desktop/desktop.c +++ b/kiwmi/desktop/desktop.c @@ -93,7 +93,6 @@ desktop_active_output(struct kiwmi_server *server) return output; } - // 2. focused view center if (!wl_list_empty(&server->desktop.views)) { struct kiwmi_view *view; @@ -104,7 +103,8 @@ desktop_active_output(struct kiwmi_server *server) double lx = view->geom.x + view->geom.width / 2; double ly = view->geom.y + view->geom.height / 2; - struct wlr_output *wlr_output = wlr_output_layout_output_at(server->desktop.output_layout, lx, ly); + struct wlr_output *wlr_output = + wlr_output_layout_output_at(server->desktop.output_layout, lx, ly); return wlr_output->data; } @@ -112,6 +112,7 @@ desktop_active_output(struct kiwmi_server *server) double lx = server->input.cursor->cursor->x; double ly = server->input.cursor->cursor->y; - struct wlr_output *wlr_output = wlr_output_layout_output_at(server->desktop.output_layout, lx, ly); + struct wlr_output *wlr_output = + wlr_output_layout_output_at(server->desktop.output_layout, lx, ly); return wlr_output->data; } diff --git a/kiwmi/desktop/layer_shell.c b/kiwmi/desktop/layer_shell.c index b2c823f..0f8139e 100644 --- a/kiwmi/desktop/layer_shell.c +++ b/kiwmi/desktop/layer_shell.c @@ -351,9 +351,8 @@ layer_shell_new_surface_notify(struct wl_listener *listener, void *data) layer_surface->namespace); if (!layer_surface->output) { - struct kiwmi_server *server = - wl_container_of(desktop, server, desktop); - layer_surface->output = desktop_active_output(server)->wlr_output; + struct kiwmi_server *server = wl_container_of(desktop, server, desktop); + layer_surface->output = desktop_active_output(server)->wlr_output; } struct kiwmi_layer *layer = malloc(sizeof(*layer)); diff --git a/kiwmi/input/seat.c b/kiwmi/input/seat.c index 5097275..008f9c0 100644 --- a/kiwmi/input/seat.c +++ b/kiwmi/input/seat.c @@ -41,28 +41,6 @@ seat_focus_surface(struct kiwmi_seat *seat, struct wlr_surface *wlr_surface) &keyboard->modifiers); } -void -seat_focus_view(struct kiwmi_seat *seat, struct kiwmi_view *view) -{ - if (!view) { - seat_focus_surface(seat, NULL); - } - - struct kiwmi_desktop *desktop = view->desktop; - - if (seat->focused_view) { - view_set_activated(seat->focused_view, false); - } - - // move view to front - wl_list_remove(&view->link); - wl_list_insert(&desktop->views, &view->link); - - seat->focused_view = view; - view_set_activated(view, true); - seat_focus_surface(seat, view->wlr_surface); -} - void seat_focus_layer(struct kiwmi_seat *seat, struct kiwmi_layer *layer) { @@ -87,6 +65,29 @@ seat_focus_layer(struct kiwmi_seat *seat, struct kiwmi_layer *layer) seat->focused_layer = layer; } +void +seat_focus_view(struct kiwmi_seat *seat, struct kiwmi_view *view) +{ + if (!view) { + seat_focus_surface(seat, NULL); + return; + } + + struct kiwmi_desktop *desktop = view->desktop; + + if (seat->focused_view) { + view_set_activated(seat->focused_view, false); + } + + // move view to front + wl_list_remove(&view->link); + wl_list_insert(&desktop->views, &view->link); + + seat->focused_view = view; + view_set_activated(view, true); + seat_focus_surface(seat, view->wlr_surface); +} + static void request_set_cursor_notify(struct wl_listener *listener, void *data) { diff --git a/kiwmi/luak/kiwmi_cursor.c b/kiwmi/luak/kiwmi_cursor.c index c15ac9f..2a1e0c7 100644 --- a/kiwmi/luak/kiwmi_cursor.c +++ b/kiwmi/luak/kiwmi_cursor.c @@ -32,7 +32,7 @@ l_kiwmi_cursor_output_at_pos(lua_State *L) struct kiwmi_server *server = cursor->server; struct wlr_output *wlr_output = wlr_output_layout_output_at( - server->desktop.output_layout,cursor->cursor->x, cursor->cursor->y); + server->desktop.output_layout, cursor->cursor->x, cursor->cursor->y); if (wlr_output) { lua_pushcfunction(L, luaK_kiwmi_output_new); diff --git a/kiwmi/luak/kiwmi_server.c b/kiwmi/luak/kiwmi_server.c index 431b582..b2c60d0 100644 --- a/kiwmi/luak/kiwmi_server.c +++ b/kiwmi/luak/kiwmi_server.c @@ -228,6 +228,19 @@ l_kiwmi_server_stop_interactive(lua_State *L) return 0; } +static int +l_kiwmi_server_unfocus(lua_State *L) +{ + struct kiwmi_object *obj = + *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_server"); + + struct kiwmi_server *server = obj->object; + + seat_focus_view(server->input.seat, NULL); + + return 0; +} + static int l_kiwmi_server_view_at(lua_State *L) { @@ -273,6 +286,7 @@ static const luaL_Reg kiwmi_server_methods[] = { {"schedule", l_kiwmi_server_schedule}, {"spawn", l_kiwmi_server_spawn}, {"stop_interactive", l_kiwmi_server_stop_interactive}, + {"unfocus", l_kiwmi_server_unfocus}, {"view_at", l_kiwmi_server_view_at}, {NULL, NULL}, }; @@ -328,7 +342,9 @@ kiwmi_server_on_output_notify(struct wl_listener *listener, void *data) } static void -kiwmi_server_on_request_active_output_notify(struct wl_listener *listener, void *data) +kiwmi_server_on_request_active_output_notify( + struct wl_listener *listener, + void *data) { struct kiwmi_lua_callback *lc = wl_container_of(listener, lc, listener); struct kiwmi_server *server = lc->server; @@ -345,7 +361,10 @@ kiwmi_server_on_request_active_output_notify(struct wl_listener *listener, void struct kiwmi_object *obj; struct kiwmi_object **objp; if (!(objp = luaK_toudata(L, -1, "kiwmi_output"))) { - wlr_log(WLR_ERROR, "kiwmi_output expected, got %s", luaL_typename(L, -1)); + wlr_log( + WLR_ERROR, + "kiwmi_output expected, got %s", + luaL_typename(L, -1)); return; } diff --git a/kiwmi/luak/luak.c b/kiwmi/luak/luak.c index 6e2c2a6..9a5b75a 100644 --- a/kiwmi/luak/luak.c +++ b/kiwmi/luak/luak.c @@ -26,11 +26,12 @@ void * luaK_toudata(lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ - lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ - lua_pop(L, 2); /* remove both metatables */ + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield( + L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ return p; } } diff --git a/lua_docs.md b/lua_docs.md index 96e28fd..e36ca46 100644 --- a/lua_docs.md +++ b/lua_docs.md @@ -53,6 +53,10 @@ Spawn a new process. Stops an interactive move or resize. +#### kiwmi:unfocus() + +Unfocus the currently focused view. + #### kiwmi:view_at(lx, ly) Get the view at a specified position.