From 8693d2dd1365cf9685891cd744e045aef534ac0b Mon Sep 17 00:00:00 2001 From: tiosgz Date: Wed, 11 Aug 2021 20:43:40 +0000 Subject: [PATCH] Add controls for verbosity level This allows the config to be exactly as verbose as kiwmi, or to change the verbosity level at runtime (e.g. using kiwmic). It uses numbers, because they are much easier to handle on both sides and add only little inconvenience to the user. --- kiwmi/luak/kiwmi_server.c | 33 +++++++++++++++++++++++++++++++++ lua_docs.md | 8 ++++++++ 2 files changed, 41 insertions(+) diff --git a/kiwmi/luak/kiwmi_server.c b/kiwmi/luak/kiwmi_server.c index b2c60d0..507257d 100644 --- a/kiwmi/luak/kiwmi_server.c +++ b/kiwmi/luak/kiwmi_server.c @@ -191,6 +191,25 @@ l_kiwmi_server_schedule(lua_State *L) return 0; } +static int +l_kiwmi_server_set_verbosity(lua_State *L) +{ + luaL_checkudata(L, 1, "kiwmi_server"); + luaL_checktype(L, 2, LUA_TNUMBER); + + int verbosity = lua_tointeger(L, 2); + + if (verbosity < WLR_SILENT) { + verbosity = WLR_SILENT; + } else if (verbosity >= WLR_LOG_IMPORTANCE_LAST) { + verbosity = WLR_DEBUG; + } + + wlr_log_init((enum wlr_log_importance)verbosity, NULL); + + return 0; +} + static int l_kiwmi_server_spawn(lua_State *L) { @@ -241,6 +260,18 @@ l_kiwmi_server_unfocus(lua_State *L) return 0; } +static int +l_kiwmi_server_verbosity(lua_State *L) +{ + luaL_checkudata(L, 1, "kiwmi_server"); + + int verbosity = (int)wlr_log_get_verbosity(); + + lua_pushinteger(L, verbosity); + + return 1; +} + static int l_kiwmi_server_view_at(lua_State *L) { @@ -284,9 +315,11 @@ static const luaL_Reg kiwmi_server_methods[] = { {"output_at", l_kiwmi_server_output_at}, {"quit", l_kiwmi_server_quit}, {"schedule", l_kiwmi_server_schedule}, + {"set_verbosity", l_kiwmi_server_set_verbosity}, {"spawn", l_kiwmi_server_spawn}, {"stop_interactive", l_kiwmi_server_stop_interactive}, {"unfocus", l_kiwmi_server_unfocus}, + {"verbosity", l_kiwmi_server_verbosity}, {"view_at", l_kiwmi_server_view_at}, {NULL, NULL}, }; diff --git a/lua_docs.md b/lua_docs.md index ee759ec..5bb8e16 100644 --- a/lua_docs.md +++ b/lua_docs.md @@ -50,6 +50,10 @@ Quit kiwmi. Call `callback` after `delay` ms. Callback get passed itself, so that it can easily reregister itself. +#### kiwmi:set_verbosity(level) + +Sets verbosity of kiwmi to the level specified with a number (see `kiwmi:verbosity()`). + #### kiwmi:spawn(command) Spawn a new process. @@ -63,6 +67,10 @@ Stops an interactive move or resize. Unfocus the currently focused view. +#### kiwmi:verbosity() + +Returns the numerical verbosity level of kiwmi (value of one of `wlr_log_importance`, silent = 0, error = 1, info = 2, debug = 3). + #### kiwmi:view_at(lx, ly) Get the view at a specified position.