diff --git a/config/init.lua b/config/init.lua index dd4fa13d..80e1802b 100644 --- a/config/init.lua +++ b/config/init.lua @@ -5,7 +5,7 @@ config.set_sloppy_focus(true) config.set_automatic_workspace_naming(true) -local termcmd = "/usr/bin/termite" +local termcmd = "/usr/bin/alacritty" local function on_start() -- execute programs or do what ever you want e.g.: diff --git a/include/keybinding.h b/include/keybinding.h index 3bfc8410..d3976c4d 100644 --- a/include/keybinding.h +++ b/include/keybinding.h @@ -18,7 +18,9 @@ struct keybinding { int lua_func_ref; }; -struct keybinding *create_keybinding(); +struct keybinding *create_keybinding(const char *binding, int lua_func_ref); +void destroy_keybinding(struct keybinding *keybinding); +void destroy_keybinding0(void *keybinding); bool handle_keybinding(int mod, int sym); diff --git a/include/lib/info/lib_info.h b/include/lib/info/lib_info.h index 3d1e113f..de70c683 100644 --- a/include/lib/info/lib_info.h +++ b/include/lib/info/lib_info.h @@ -5,6 +5,7 @@ int lib_get_active_layout(lua_State *L); int lib_get_container_under_cursor(lua_State *L); +int lib_get_n_tiled(lua_State *L); int lib_get_next_empty_workspace(lua_State *L); int lib_get_nmaster(lua_State *L); int lib_get_previous_layout(lua_State *L); diff --git a/include/monitor.h b/include/monitor.h index e8891f09..36ea08b5 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -4,8 +4,7 @@ #include #include -#include "root.h" -#include "tagset.h" +#include "bitset/bitset.h" struct cursor; diff --git a/include/options.h b/include/options.h index 502e6210..94fcb154 100644 --- a/include/options.h +++ b/include/options.h @@ -67,6 +67,7 @@ struct options { }; struct options get_default_options(); +void load_default_keybindings(); GPtrArray *create_tagnames(); void copy_options(struct options *dest_option, struct options *src_option); diff --git a/include/utils/parseConfigUtils.h b/include/utils/parseConfigUtils.h index 3d4e4e14..62aced13 100644 --- a/include/utils/parseConfigUtils.h +++ b/include/utils/parseConfigUtils.h @@ -6,16 +6,12 @@ #include #include -#include "utils/coreUtils.h" -#include "layout.h" -#include "rules/rule.h" -#include "rules/mon_rule.h" - GPtrArray *create_default_config_paths(); /* returns 0 if loading file was successful else return 1 * the error_file argument gets malloced so it has to be freed */ int load_config(lua_State *L); +void load_default_lua_config(lua_State *L); int init_utils(lua_State *L); void init_error_file(); void close_error_file(); diff --git a/man/japokwm.5.scd b/man/japokwm.5.scd index bb740a3c..ec11fd28 100644 --- a/man/japokwm.5.scd +++ b/man/japokwm.5.scd @@ -370,6 +370,11 @@ integers ++ integer - container id +*get_n_tiled()* ++ + get the amount of containers currently visible ++ + ++ + integer - amount of containers + *is_container_not_in_limit()* ++ returns whether a container doesn't violate min/max_width/height of the constraints ++ diff --git a/src/client.c b/src/client.c index 1299bb8e..5f705151 100644 --- a/src/client.c +++ b/src/client.c @@ -14,6 +14,8 @@ #include "ipc-server.h" #include "workspace.h" #include "scratchpad.h" +#include "monitor.h" +#include "tagset.h" struct client *create_client(enum shell shell_type, union surface_t surface) { @@ -240,10 +242,6 @@ void client_handle_set_title(struct wl_listener *listener, void *data) void client_handle_set_app_id(struct wl_listener *listener, void *data) { - debug_print("set app id\n"); - debug_print("set app id\n"); - debug_print("set app id\n"); - debug_print("set app id\n"); struct client *c = wl_container_of(listener, c, set_app_id); const char *app_id; /* rule matching */ diff --git a/src/command.c b/src/command.c index 7adbbead..a9017f11 100644 --- a/src/command.c +++ b/src/command.c @@ -3,6 +3,7 @@ #include #include "utils/parseConfigUtils.h" +#include "server.h" struct cmd_results *cmd_results_new(enum cmd_status status, const char *format, ...) { diff --git a/src/event_handler.c b/src/event_handler.c index bea0372d..2b99c27b 100644 --- a/src/event_handler.c +++ b/src/event_handler.c @@ -3,6 +3,7 @@ #include #include "utils/parseConfigUtils.h" +#include "utils/coreUtils.h" struct event_handler *create_event_handler() { diff --git a/src/keybinding.c b/src/keybinding.c index 0e086471..5507b12c 100644 --- a/src/keybinding.c +++ b/src/keybinding.c @@ -9,6 +9,7 @@ #include "utils/parseConfigUtils.h" #include "stringop.h" #include "workspace.h" +#include "monitor.h" const char *mods[8] = {"Shift_L", "Caps_Lock", "Control_L", "Alt_L", "", "", "Super_L", "ISO_Level3_Shift"}; const char *modkeys[4] = {"Alt_L", "Num_Lock", "ISO_Level3_Shift", "Super_L"}; @@ -192,12 +193,28 @@ static bool process_binding(lua_State *L, const char *bind, GPtrArray *keybindin return handled; } -struct keybinding *create_keybinding() +struct keybinding *create_keybinding(const char *binding, int lua_func_ref) { struct keybinding *keybinding = calloc(1, sizeof(struct keybinding)); + keybinding->binding = strdup(binding); + keybinding->lua_func_ref = lua_func_ref; return keybinding; } +void destroy_keybinding(struct keybinding *keybinding) +{ + free(keybinding->binding); + if (keybinding->lua_func_ref > 0) { + luaL_unref(L, LUA_REGISTRYINDEX, keybinding->lua_func_ref); + } + free(keybinding); +} + +void destroy_keybinding0(void *keybinding) +{ + destroy_keybinding(keybinding); +} + static int millisec_get_available_seconds(int milli_sec) { int available_seconds = milli_sec/1000; diff --git a/src/layer_shell.c b/src/layer_shell.c index 22c7400c..c42c567a 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -11,6 +11,8 @@ #include "tile/tileUtils.h" #include "render/render.h" #include "input_manager.h" +#include "root.h" +#include "tagset.h" void create_notify_layer_shell(struct wl_listener *listener, void *data) { diff --git a/src/lib/actions/lib_actions.c b/src/lib/actions/lib_actions.c index c5f5bfae..241dae6a 100644 --- a/src/lib/actions/lib_actions.c +++ b/src/lib/actions/lib_actions.c @@ -25,6 +25,7 @@ #include "workspace.h" #include "xdg-shell-protocol.h" #include "scratchpad.h" +#include "tagset.h" int lib_arrange(lua_State *L) { diff --git a/src/lib/config/lib_config.c b/src/lib/config/lib_config.c index 9e444a02..31bc7992 100644 --- a/src/lib/config/lib_config.c +++ b/src/lib/config/lib_config.c @@ -13,7 +13,12 @@ int lib_reload(lua_State *L) { + close_error_file(); + init_error_file(); + server.default_layout->options = get_default_options(); + g_ptr_array_free(server.default_layout->options.keybindings, TRUE); + server.default_layout->options.keybindings = g_ptr_array_new(); remove_loaded_layouts(server.workspaces); load_config(L); @@ -196,9 +201,11 @@ int lib_add_mon_rule(lua_State *L) int lib_bind_key(lua_State *L) { - struct keybinding *keybinding = create_keybinding(); - lua_ref_safe(L, LUA_REGISTRYINDEX, &keybinding->lua_func_ref); - keybinding->binding = strdup(luaL_checkstring(L, -1)); + int lua_func_ref = 0; + lua_ref_safe(L, LUA_REGISTRYINDEX, &lua_func_ref); + const char *binding = luaL_checkstring(L, -1); + + struct keybinding *keybinding = create_keybinding(binding, lua_func_ref); lua_pop(L, 1); g_ptr_array_add(server.default_layout->options.keybindings, keybinding); return 0; diff --git a/src/lib/info/lib_info.c b/src/lib/info/lib_info.c index 1aa8da50..f3dd964b 100644 --- a/src/lib/info/lib_info.c +++ b/src/lib/info/lib_info.c @@ -8,6 +8,9 @@ #include "server.h" #include "tile/tileUtils.h" #include "workspace.h" +#include "layout.h" +#include "tagset.h" +#include "root.h" int lib_get_active_layout(lua_State *L) { @@ -29,6 +32,16 @@ int lib_get_this_container_count(lua_State *L) return 1; } +int lib_get_n_tiled(lua_State *L) +{ + struct monitor *m = selected_monitor; + struct tagset *tagset = monitor_get_active_tagset(m); + struct layout *lt = tagset_get_layout(tagset); + int i = lt->n_tiled; + lua_pushinteger(L, i); + return 1; +} + int lib_this_container_position(lua_State *L) { struct monitor *m = selected_monitor; diff --git a/src/monitor.c b/src/monitor.c index fc8a8d76..deb5fee6 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -16,6 +16,9 @@ #include "workspace.h" #include "utils/parseConfigUtils.h" #include "layer_shell.h" +#include "rules/mon_rule.h" +#include "root.h" +#include "tagset.h" struct wl_list sticky_stack; diff --git a/src/options.c b/src/options.c index 67c32a26..30b19d98 100644 --- a/src/options.c +++ b/src/options.c @@ -4,6 +4,7 @@ #include #include "client.h" +#include "server.h" #include "utils/coreUtils.h" #include "layout.h" #include "keybinding.h" @@ -60,10 +61,45 @@ struct options get_default_options() }; options.tag_names = create_tagnames(); - options.keybindings = g_ptr_array_new(); + options.keybindings = g_ptr_array_new_with_free_func(destroy_keybinding0); return options; } +static struct keybinding *create_keybind(const char *binding, const char *command) +{ + int ref = 0; + char *cmd = g_strconcat("return function() ", command, " end", NULL); + luaL_dostring(L, cmd); + lua_ref_safe(L, LUA_REGISTRYINDEX, &ref); + free(cmd); + struct keybinding *keybinding = create_keybinding(binding, ref); + return keybinding; +} + +static void add_keybind(GPtrArray *keybindings, const char *binding, const char *command) +{ + struct keybinding *keybinding = create_keybind(binding, command); + g_ptr_array_add(keybindings, keybinding); +} + +void load_default_keybindings() +{ + struct layout *lt = server.default_layout; + struct options *options = <->options; + GPtrArray *keybindings = options->keybindings; + + add_keybind(keybindings, "mod-S-q", "action.quit()"); + add_keybind(keybindings, "mod-r", "config.reload()"); + add_keybind(keybindings, "mod-S-c", "action.kill(info.this_container_position())"); + add_keybind(keybindings, "mod-S-Return", "action.exec(\"/usr/bin/alacritty\")"); + add_keybind(keybindings, "mod-j", "action.focus_on_stack(1)"); + add_keybind(keybindings, "mod-k", "action.focus_on_stack(-1)"); + add_keybind(keybindings, "mod-Return", "action.zoom()"); + add_keybind(keybindings, "mod-S-h", "action.resize_main(-1/10)"); + add_keybind(keybindings, "mod-S-l", "action.resize_main(1/10)"); + return; +} + void copy_options(struct options *dest_option, struct options *src_option) { memcpy(dest_option, src_option, sizeof(struct options)); diff --git a/src/render/render.c b/src/render/render.c index 5a835b07..967ddfa8 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -21,6 +21,7 @@ #include "utils/gapUtils.h" #include "layer_shell.h" #include "workspace.h" +#include "tagset.h" struct wlr_renderer *drw; struct render_data render_data; diff --git a/src/rules/mon_rule.c b/src/rules/mon_rule.c index 1de9f884..0add4a7a 100644 --- a/src/rules/mon_rule.c +++ b/src/rules/mon_rule.c @@ -4,6 +4,7 @@ #include #include "utils/parseConfigUtils.h" +#include "server.h" struct mon_rule *create_mon_rule(const char *output_name, int lua_func_ref) { diff --git a/src/scratchpad.c b/src/scratchpad.c index ce40af24..7bd209d8 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -5,6 +5,7 @@ #include "server.h" #include "tile/tileUtils.h" #include "workspace.h" +#include "tagset.h" // TODO rewrite this function so it is easier to read void move_to_scratchpad(struct container *con, int position) diff --git a/src/tagset.c b/src/tagset.c index 4bed1458..2a1fcc10 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -17,6 +17,9 @@ #include "list_sets/focus_stack_set.h" #include "list_sets/container_stack_set.h" #include "workspace.h" +#include "tagset.h" +#include "workspace.h" +#include "root.h" static void tagset_assign_workspace(struct tagset *tagset, struct workspace *ws, bool load); static void tagset_assign_workspaces(struct tagset *tagset, BitSet *workspaces); diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index 392879ac..c22e5a4f 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -22,6 +22,7 @@ #include "layer_shell.h" #include "workspace.h" #include "list_sets/focus_stack_set.h" +#include "tagset.h" static void arrange_container(struct container *con, struct monitor *m, int arrange_position, struct wlr_box root_geom, int inner_gap); diff --git a/src/translationLayer.c b/src/translationLayer.c index bbf3cfcc..96886dfa 100644 --- a/src/translationLayer.c +++ b/src/translationLayer.c @@ -79,6 +79,7 @@ static const struct luaL_Reg info[] = { {"get_active_layout", lib_get_active_layout}, {"get_container_under_cursor", lib_get_container_under_cursor}, + {"get_n_tiled", lib_get_n_tiled}, {"get_next_empty_workspace", lib_get_next_empty_workspace}, {"get_nmaster", lib_get_nmaster}, {"get_previous_layout", lib_get_previous_layout}, diff --git a/src/utils/parseConfigUtils.c b/src/utils/parseConfigUtils.c index 7c95df59..31f7bfc2 100644 --- a/src/utils/parseConfigUtils.c +++ b/src/utils/parseConfigUtils.c @@ -20,6 +20,8 @@ #include "stringop.h" #include "utils/coreUtils.h" #include "rules/mon_rule.h" +#include "workspace.h" +#include "rules/rule.h" static const char *plugin_relative_paths[] = { "autoload", @@ -27,7 +29,7 @@ static const char *plugin_relative_paths[] = { }; static const char *config_file = "init.lua"; -static const char *error_file = "$HOME/.config/japokwm/init.err"; +static const char *error_file = "init.err"; static int error_fd = -1; static int load_file(lua_State *L, const char *file); @@ -149,6 +151,13 @@ int load_config(lua_State *L) return success; } +void load_default_lua_config(lua_State *L) +{ + server.default_layout->options = get_default_options(); + remove_loaded_layouts(server.workspaces); + load_default_keybindings(); +} + // returns 0 upon success and 1 upon failure int init_utils(lua_State *L) { @@ -176,11 +185,13 @@ int init_utils(lua_State *L) void init_error_file() { - char *ef = get_config_file(error_file); - char *ef_dir = dirname(ef); + char *ef_dir = get_config_dir(error_file); mkdir(ef_dir, 0777); + char *ef = strdup(ef_dir); + join_path(&ef, error_file); error_fd = open(ef, O_WRONLY | O_CREAT | O_TRUNC, 0644); free(ef); + free(ef_dir); } void close_error_file() @@ -239,8 +250,11 @@ void notify_msg(const char *msg) void handle_error(const char *msg) { notify_msg(msg); + printf("%s\n", msg); + load_default_lua_config(L); + debug_print("error_fd: %i\n", error_fd); // if error file not initialized if (error_fd < 0) return; diff --git a/src/workspace.c b/src/workspace.c index d9923022..77cc765d 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -18,6 +18,7 @@ #include "list_sets/list_set.h" #include "list_sets/focus_stack_set.h" #include "list_sets/visual_stack_set.h" +#include "tagset.h" static void update_workspaces_id(GPtrArray *workspaces) { @@ -433,10 +434,8 @@ void load_layout(lua_State *L, const char *name) if (found) { lt = g_ptr_array_steal_index(ws->loaded_layouts, i); g_ptr_array_insert(ws->loaded_layouts, 0, lt); - debug_print("steal\n"); push_layout(ws, lt); } else { - debug_print("create layout\n"); lt = create_layout(L); copy_layout_safe(lt, server.default_layout); diff --git a/src/xwayland.c b/src/xwayland.c index 29c376ec..416dee5b 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -11,6 +11,7 @@ #include "seat.h" #include "workspace.h" #include "list_sets/focus_stack_set.h" +#include "tagset.h" #if JAPOKWM_HAS_XWAYLAND static const char *atom_map[ATOM_LAST] = {