Skip to content

Commit

Permalink
lua functions fix, config fix, Makefile changes, nix support
Browse files Browse the repository at this point in the history
  • Loading branch information
danihek committed Aug 3, 2024
1 parent acfa48f commit abc032c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 81 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner)
LIBS=\
$(shell pkg-config --cflags --libs "wlroots-0.19") \
$(shell pkg-config --cflags --libs "wlroots-0.18") \
$(shell pkg-config --cflags --libs wayland-server) \
$(shell pkg-config --cflags --libs xkbcommon) \
-llua \
-lxcb
$(shell pkg-config --cflags --libs lua) \
$(shell pkg-config --cflags --libs xcb) \

wlr-layer-shell-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) server-header \
Expand Down Expand Up @@ -34,8 +34,8 @@ SRC=\
./src/lua/exposed_functions.c

ARGS=\
-Werror \
-DWLR_USE_UNSTABLE
# -Werror \
XWAYLAND=\
-DXWAYLAND
Expand All @@ -53,4 +53,4 @@ hellcli: src/hellcli/hellcli.c

.PHONY: clean
clean:
rm -f hellwm hellcli xdg-shell-protocol.h xdg-shell-protocol.c wlr-layer-shell-unstable-v1-protocol.h hellwmlog.log
rm -f hellwm hellcli xdg-shell-protocol.h xdg-shell-protocol.c wlr-layer-shell-unstable-v1-protocol.h logfile.log
17 changes: 16 additions & 1 deletion shell-hellwm.nix → default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@ with nixpkgs; mkShell {

nativeBuildInputs = [
lua
gdb
udev
libg
glib
glibc
clang
libGL
libGLU
pixman
libutil
glxinfo
gnumake
libllvm
llvm_18
wayland
pkg-config
xorg.libxcb
libxkbcommon
xorg.xcbutilwm
wayland-scanner
wayland-protocols
unstable.wlroots_0_18
];
buildInputs = [ ];

buildInputs = [];
}
52 changes: 23 additions & 29 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
/* purpose of this boolean define is just because this thing down there looks with it cool :) */
#define boolean bool

#define tINT *((int *)
#define tCHAR *((char *)
#define tFLOAT *((float *)
#define tUINT8 *((uint8_t*)
#define tDOUBLE *((double *)
#define tBOOLEAN *((boolean *)

struct hellwm_config_binds global_keybinds;
struct hellwm_server *global_server;

Expand Down Expand Up @@ -148,7 +141,7 @@ void hellwm_config_set_decoration(lua_State *L)
{
if (hellwm_luaGetTable(L, (char*)hellwm_config_groups_arr[HELLWM_CONFIG_DECORATION]))
{
uint8_t window_decoration_mode = tUINT8 hellwm_luaGetField(L, "window_decoration_mode", LUA_TNUMBER));
uint8_t window_decoration_mode = (int)hellwm_luaGetFieldInteger(L, "window_decoration_mode");

global_server->default_decoration_mode = window_decoration_mode;
}
Expand All @@ -157,7 +150,6 @@ void hellwm_config_set_decoration(lua_State *L)
global_server->default_decoration_mode = 2; /* Server side */
}


hellwm_log(
HELLWM_LOG,
"Decoration settings: window_decoration_mode: %d",
Expand Down Expand Up @@ -191,20 +183,20 @@ void hellwm_config_set_monitor(lua_State *L, struct wlr_output *output)
wlr_output_state_set_enabled(&state, true);
struct wlr_output_mode *mode = wlr_output_preferred_mode(output);

int32_t lx = 0, ly = 0;
int lx = 0, ly = 0;

if (hellwm_luaGetTable(L, name))
{
int32_t width = tFLOAT hellwm_luaGetField(L, "width", LUA_TNUMBER));
int32_t height = tFLOAT hellwm_luaGetField(L, "height", LUA_TNUMBER));
int32_t hz = (int32_t)tFLOAT hellwm_luaGetField(L, "hz", LUA_TNUMBER));
int32_t transfrom = tFLOAT hellwm_luaGetField(L, "transfrom", LUA_TNUMBER));

lx = (int32_t) tFLOAT hellwm_luaGetField(L, "x", LUA_TNUMBER));
ly = (int32_t) tFLOAT hellwm_luaGetField(L, "y", LUA_TNUMBER));
int width = hellwm_luaGetFieldInteger(L, "width");
int height = hellwm_luaGetFieldInteger(L, "height");
int hz = hellwm_luaGetFieldInteger(L, "hz");
int transfrom = hellwm_luaGetFieldInteger(L, "transfrom");

float scale = tFLOAT hellwm_luaGetField(L, "scale", LUA_TNUMBER));
bool vrr = tBOOLEAN hellwm_luaGetField(L, "vrr", LUA_TBOOLEAN));
lx = hellwm_luaGetFieldInteger(L, "x");
ly = hellwm_luaGetFieldInteger(L, "y");

float scale = hellwm_luaGetFieldFloat(L, "scale");
bool vrr = hellwm_luaGetFieldBool(L, "vrr");

switch (transfrom)
{
Expand Down Expand Up @@ -297,14 +289,14 @@ void hellwm_config_set_keyboard(lua_State *L, struct wlr_keyboard *keyboard)

if (hellwm_luaGetTable(L, (char*)hellwm_config_groups_arr[HELLWM_CONFIG_KEYBOARD]))
{
char * rules = hellwm_luaGetField(L, "rules", LUA_TSTRING);
char * model = hellwm_luaGetField(L, "model", LUA_TSTRING);
char * layout = hellwm_luaGetField(L, "layout", LUA_TSTRING);
char * variant = hellwm_luaGetField(L, "variant", LUA_TSTRING);
char * options = hellwm_luaGetField(L, "options", LUA_TSTRING);
char * rules = hellwm_luaGetFieldString(L, "rules");
char * model = hellwm_luaGetFieldString(L, "model");
char * layout = hellwm_luaGetFieldString(L, "layout");
char * variant = hellwm_luaGetFieldString(L, "variant");
char * options = hellwm_luaGetFieldString(L, "options");

int delay = tFLOAT hellwm_luaGetField(L, "delay", LUA_TNUMBER));
int rate = tFLOAT hellwm_luaGetField(L, "rate", LUA_TNUMBER));
int delay = hellwm_luaGetFieldInteger(L, "delay");
int rate = hellwm_luaGetFieldInteger(L, "rate");

rule_names.rules = rules;
rule_names.model = model;
Expand All @@ -315,10 +307,12 @@ void hellwm_config_set_keyboard(lua_State *L, struct wlr_keyboard *keyboard)
wlr_keyboard_set_repeat_info(keyboard,rate,delay);

hellwm_log(
HELLWM_LOG,
"New Keyboard: %s, layout: %s",
HELLWM_DEBUG,
"New Keyboard: %s, layout: %s, delay: %d, rate: %d",
keyboard->base.name,
layout
layout,
delay,
rate
);
}
else
Expand Down
99 changes: 54 additions & 45 deletions src/lua/lua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,58 +43,67 @@ int hellwm_luaGetTable(lua_State *L, char *tableName)
* Assuming table is at top of stack,
* we just use lua_getglobal() before calling this function
*/
void *hellwm_luaGetField(lua_State *L, char *fieldName, int lua_variableType)
char* hellwm_luaGetFieldString(lua_State *L, char *fieldName)
{
void *temp;
char *string_val = "";

lua_pushstring(L, fieldName);
lua_gettable(L, -2);

switch (lua_variableType)
if (lua_isstring(L, -1))
{
case LUA_TNUMBER:
if (lua_isnumber(L, -1))
{
float val = lua_tonumber(L,-1);
temp = (void *)&val;
}
else
{
float *val = NULL;
temp = (void*)&val;
}
break;

case LUA_TBOOLEAN:
if (lua_isboolean(L, -1))
{
bool val = lua_toboolean(L,-1);
temp = (void *)&val;
}
else
{
bool *val = false;
temp = (void*)&val;
}
break;

case LUA_TSTRING:
if (lua_isstring(L, -1))
{
const char *val = lua_tostring(L, -1);
temp = (void*)val;
}
else
{
const char *val = NULL;
temp = (void*)val;
}
break;
default:
temp = NULL;
}
string_val = lua_tostring(L, -1);
}

lua_pop(L,1);
return string_val;
}

bool hellwm_luaGetFieldBool(lua_State *L, char *fieldName)
{
bool bool_val = 0;
lua_pushstring(L, fieldName);
lua_gettable(L, -2);

if (lua_isboolean(L, -1))
{
bool_val = lua_toboolean(L,-1);
}

lua_pop(L,1);
return bool_val;
}

int hellwm_luaGetFieldInteger(lua_State *L, char *fieldName)
{
int int_val = 0;

lua_pushstring(L, fieldName);
lua_gettable(L, -2);

if (lua_isnumber(L, -1))
{
int_val = lua_tonumber(L,-1);
}

lua_pop(L,1);
return int_val;
}

float hellwm_luaGetFieldFloat(lua_State *L, char *fieldName)
{
float float_val = 0;

lua_pushstring(L, fieldName);
lua_gettable(L, -2);

if (lua_isnumber(L, -1))
{
float float_val = lua_tonumber(L,-1);
}

lua_pop(L,1);
return temp;
return float_val;
}

void hellwm_luaGetTableField(lua_State *L, char *tableName, char *fieldName)
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#include "../src/lua/lua_util.c"
#include "../src/workspaces.c"

#define LOGPATH "hellwmlog.log" // TODO: change to tmp
#define LOGPATH "logfile.log" // TODO: change to tmp

typedef void (*FunctionPtr)();

Expand Down

0 comments on commit abc032c

Please sign in to comment.