Add kiwmi:unfocus(), clang-format

This commit is contained in:
buffet 2021-08-09 18:53:35 +00:00
parent 4322717ba7
commit c45dd269e7
7 changed files with 61 additions and 36 deletions

View file

@ -93,7 +93,6 @@ desktop_active_output(struct kiwmi_server *server)
return output; return output;
} }
// 2. focused view center // 2. focused view center
if (!wl_list_empty(&server->desktop.views)) { if (!wl_list_empty(&server->desktop.views)) {
struct kiwmi_view *view; 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 lx = view->geom.x + view->geom.width / 2;
double ly = view->geom.y + view->geom.height / 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; return wlr_output->data;
} }
@ -112,6 +112,7 @@ desktop_active_output(struct kiwmi_server *server)
double lx = server->input.cursor->cursor->x; double lx = server->input.cursor->cursor->x;
double ly = server->input.cursor->cursor->y; 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; return wlr_output->data;
} }

View file

@ -351,8 +351,7 @@ layer_shell_new_surface_notify(struct wl_listener *listener, void *data)
layer_surface->namespace); layer_surface->namespace);
if (!layer_surface->output) { if (!layer_surface->output) {
struct kiwmi_server *server = struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
wl_container_of(desktop, server, desktop);
layer_surface->output = desktop_active_output(server)->wlr_output; layer_surface->output = desktop_active_output(server)->wlr_output;
} }

View file

@ -41,28 +41,6 @@ seat_focus_surface(struct kiwmi_seat *seat, struct wlr_surface *wlr_surface)
&keyboard->modifiers); &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 void
seat_focus_layer(struct kiwmi_seat *seat, struct kiwmi_layer *layer) 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; 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 static void
request_set_cursor_notify(struct wl_listener *listener, void *data) request_set_cursor_notify(struct wl_listener *listener, void *data)
{ {

View file

@ -32,7 +32,7 @@ l_kiwmi_cursor_output_at_pos(lua_State *L)
struct kiwmi_server *server = cursor->server; struct kiwmi_server *server = cursor->server;
struct wlr_output *wlr_output = wlr_output_layout_output_at( 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) { if (wlr_output) {
lua_pushcfunction(L, luaK_kiwmi_output_new); lua_pushcfunction(L, luaK_kiwmi_output_new);

View file

@ -228,6 +228,19 @@ l_kiwmi_server_stop_interactive(lua_State *L)
return 0; 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 static int
l_kiwmi_server_view_at(lua_State *L) l_kiwmi_server_view_at(lua_State *L)
{ {
@ -273,6 +286,7 @@ static const luaL_Reg kiwmi_server_methods[] = {
{"schedule", l_kiwmi_server_schedule}, {"schedule", l_kiwmi_server_schedule},
{"spawn", l_kiwmi_server_spawn}, {"spawn", l_kiwmi_server_spawn},
{"stop_interactive", l_kiwmi_server_stop_interactive}, {"stop_interactive", l_kiwmi_server_stop_interactive},
{"unfocus", l_kiwmi_server_unfocus},
{"view_at", l_kiwmi_server_view_at}, {"view_at", l_kiwmi_server_view_at},
{NULL, NULL}, {NULL, NULL},
}; };
@ -328,7 +342,9 @@ kiwmi_server_on_output_notify(struct wl_listener *listener, void *data)
} }
static void 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_lua_callback *lc = wl_container_of(listener, lc, listener);
struct kiwmi_server *server = lc->server; 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 *obj;
struct kiwmi_object **objp; struct kiwmi_object **objp;
if (!(objp = luaK_toudata(L, -1, "kiwmi_output"))) { 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; return;
} }

View file

@ -28,7 +28,8 @@ luaK_toudata(lua_State *L, int ud, const char *tname)
void *p = lua_touserdata(L, ud); void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */ if (p != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ lua_getfield(
L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
lua_pop(L, 2); /* remove both metatables */ lua_pop(L, 2); /* remove both metatables */
return p; return p;

View file

@ -53,6 +53,10 @@ Spawn a new process.
Stops an interactive move or resize. Stops an interactive move or resize.
#### kiwmi:unfocus()
Unfocus the currently focused view.
#### kiwmi:view_at(lx, ly) #### kiwmi:view_at(lx, ly)
Get the view at a specified position. Get the view at a specified position.