Skip to content

Commit

Permalink
Merge pull request #24 from werererer/development
Browse files Browse the repository at this point in the history
update v0.3.6
  • Loading branch information
werererer authored Sep 24, 2021
2 parents 2c1419e + 155b9a5 commit 7f5b338
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
Expand Down
4 changes: 3 additions & 1 deletion include/keybinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions include/lib/info/lib_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions include/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output_damage.h>

#include "root.h"
#include "tagset.h"
#include "bitset/bitset.h"

struct cursor;

Expand Down
1 change: 1 addition & 0 deletions include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 1 addition & 5 deletions include/utils/parseConfigUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
#include <lualib.h>
#include <lauxlib.h>

#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();
Expand Down
5 changes: 5 additions & 0 deletions man/japokwm.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ integers
<return> ++
integer - container id

*get_n_tiled()* ++
get the amount of containers currently visible ++
<return> ++
integer - amount of containers

*is_container_not_in_limit()* ++
returns whether a container doesn't violate min/max_width/height of the
constraints ++
Expand Down
6 changes: 2 additions & 4 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <json-c/json.h>

#include "utils/parseConfigUtils.h"
#include "server.h"

struct cmd_results *cmd_results_new(enum cmd_status status,
const char *format, ...) {
Expand Down
1 change: 1 addition & 0 deletions src/event_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <lua.h>

#include "utils/parseConfigUtils.h"
#include "utils/coreUtils.h"

struct event_handler *create_event_handler()
{
Expand Down
19 changes: 18 additions & 1 deletion src/keybinding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/layer_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/actions/lib_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "workspace.h"
#include "xdg-shell-protocol.h"
#include "scratchpad.h"
#include "tagset.h"

int lib_arrange(lua_State *L)
{
Expand Down
13 changes: 10 additions & 3 deletions src/lib/config/lib_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/lib/info/lib_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 37 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <glib.h>

#include "client.h"
#include "server.h"
#include "utils/coreUtils.h"
#include "layout.h"
#include "keybinding.h"
Expand Down Expand Up @@ -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 = &lt->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));
Expand Down
1 change: 1 addition & 0 deletions src/render/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/rules/mon_rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>

#include "utils/parseConfigUtils.h"
#include "server.h"

struct mon_rule *create_mon_rule(const char *output_name, int lua_func_ref)
{
Expand Down
1 change: 1 addition & 0 deletions src/scratchpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/tagset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/tile/tileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/translationLayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
20 changes: 17 additions & 3 deletions src/utils/parseConfigUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
#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",
"plugins",
};

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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7f5b338

Please sign in to comment.