Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set-title events for views #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/desktop/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct kiwmi_view {
struct wl_listener destroy;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener set_title;

bool mapped;

Expand All @@ -60,6 +61,7 @@ struct kiwmi_view {
struct wl_signal request_resize;
struct wl_signal post_render;
struct wl_signal pre_render;
struct wl_signal set_title;
} events;

struct kiwmi_xdg_decoration *decoration;
Expand Down
1 change: 1 addition & 0 deletions kiwmi/desktop/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ view_create(
wl_signal_init(&view->events.request_resize);
wl_signal_init(&view->events.post_render);
wl_signal_init(&view->events.pre_render);
wl_signal_init(&view->events.set_title);

view->desktop_surface.tree = wlr_scene_tree_create(
&view->desktop->strata[KIWMI_STRATUM_NORMAL]->node);
Expand Down
10 changes: 10 additions & 0 deletions kiwmi/desktop/xdg_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ xdg_toplevel_request_resize_notify(struct wl_listener *listener, void *data)
wl_signal_emit(&view->events.request_resize, &new_event);
}

static void
xdg_toplevel_set_title_notify(struct wl_listener *listener, void *UNUSED(data))
{
struct kiwmi_view *view = wl_container_of(listener, view, set_title);
wl_signal_emit(&view->events.set_title, view);
}

static void
xdg_shell_view_close(struct kiwmi_view *view)
{
Expand Down Expand Up @@ -258,6 +265,9 @@ xdg_shell_new_surface_notify(struct wl_listener *listener, void *data)

wlr_xdg_surface_get_geometry(view->xdg_surface, &view->geom);

view->set_title.notify = xdg_toplevel_set_title_notify;
wl_signal_add(&xdg_surface->toplevel->events.set_title, &view->set_title);

wl_list_insert(&desktop->views, &view->link);
}

Expand Down
57 changes: 57 additions & 0 deletions kiwmi/luak/kiwmi_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,32 @@ kiwmi_view_on_request_resize_notify(struct wl_listener *listener, void *data)
}
}

static void
kiwmi_view_on_set_title_notify(struct wl_listener *listener, void *data)
{
struct kiwmi_lua_callback *lc = wl_container_of(listener, lc, listener);
struct kiwmi_server *server = lc->server;
lua_State *L = server->lua->L;
struct kiwmi_view *view = data;

lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);

lua_pushcfunction(L, luaK_kiwmi_view_new);
lua_pushlightuserdata(L, server->lua);
lua_pushlightuserdata(L, view);

if (lua_pcall(L, 2, 1, 0)) {
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
return;
}

if (lua_pcall(L, 1, 0, 0)) {
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
}
}

static int
l_kiwmi_view_on_destroy(lua_State *L)
{
Expand Down Expand Up @@ -665,12 +691,43 @@ l_kiwmi_view_on_request_resize(lua_State *L)
return 0;
}

static int
l_kiwmi_view_on_set_title(lua_State *L)
{
struct kiwmi_object *obj =
*(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_view");
luaL_checktype(L, 2, LUA_TFUNCTION);

if (!obj->valid) {
return luaL_error(L, "kiwmi_view no longer valid");
}

struct kiwmi_view *view = obj->object;
struct kiwmi_desktop *desktop = view->desktop;
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);

lua_pushcfunction(L, luaK_kiwmi_lua_callback_new);
lua_pushlightuserdata(L, server);
lua_pushvalue(L, 2);
lua_pushlightuserdata(L, kiwmi_view_on_set_title_notify);
lua_pushlightuserdata(L, &view->events.set_title);
lua_pushlightuserdata(L, obj);

if (lua_pcall(L, 5, 0, 0)) {
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
return 0;
}

return 0;
}

static const luaL_Reg kiwmi_view_events[] = {
{"destroy", l_kiwmi_view_on_destroy},
{"post_render", l_kiwmi_view_on_post_render},
{"pre_render", l_kiwmi_view_on_pre_render},
{"request_move", l_kiwmi_view_on_request_move},
{"request_resize", l_kiwmi_view_on_request_resize},
{"set_title", l_kiwmi_view_on_set_title},
{NULL, NULL},
};

Expand Down
5 changes: 5 additions & 0 deletions lua_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,8 @@ Callback receives the view.

The view wants to start an interactive resize.
Callback receives a table containing the `view`, and `edges`, containing the edges.

#### set_title

The view's title has changed.
Callback receives the view.