TimUntersberger / nog

A tiling window manager for Windows
MIT License
697 stars 20 forks source link

Adding support for lua #256

Closed TimUntersberger closed 3 years ago

TimUntersberger commented 3 years ago

I recently tried to do Advent Of Code in nogscript and holy shit the AST based interpreter is really slow. Right now we might not notice the performance problems, but someone in the future might want to implement a more performance heavy plugin which won't be possible, because the interpreter is so slow (This is also important for being able to write a custom layout manager in the config)

Now we have a few options:

  1. Implement a bytecode compiler + interpreter
  2. Use something like luajit (like neovim)

To be honest I don't want to do the first option, because of the time required to do this properly.

I played a bit with how a lua config could look like and this is my current result:

local direction_keys = {
  H = "Left",
  J = "Down",
  K = "Up",
  L = "Right"
}

local workspace_count = 10

nog.config.bar.font = "CaskaydiaCove NF"
nog.config.bar.font_size = 18

nog.config.work_mode = false
nog.config.display_app_bar = true
nog.config.launch_on_startup = true
nog.config.multi_monitor = true
nog.config.remove_task_bar = true

nog.config.workspaces = {
  1 = {
    text = "  "
  },
  2 = {
    text = "  ",
    monitor = 1
  },
  3 = {
    text = " 阮 "
  },
  4 = {
    text = " ﭮ "
  },
}

nog.config.rules = {
  "explorer.exe" = { 
    ignore = true 
  },
  "Taskmgr.exe" = { 
    ignore = true 
  },
  "SnippingTool.exe" = { 
    ignore = true 
  },
  "firefox.exe" = {
    has_custom_titlebar = true,
    workspace_id = 2,
    firefox = true
  },
  "chrome.exe" = {
    has_custom_titlebar = true,
    workspace_id = 2,
    chromium = true
  },
  "Discord.exe" = {
    has_custom_titlebar = true
  },
  "Spotify.exe" = {
    has_custom_titlebar = true
  },
  "Code.exe" = {
    has_custom_titlebar = true
  },
}

nog.wbind("F1", function()
  nog.launch("notepad.exe")
end)

nog.nbind("Alt+I", nog.win_ignore)
nog.nbind("Alt+Q", nog.win_close)
nog.nbind("Alt+M", nog.win_minimize)
nog.nbind("Alt+X", nog.quit)

nog.nbind("Alt+R", function() 
  nog.toggle_mode("resize")
end)

nog.nbind_map("Alt", nog.ws_focus, direction_keys)
nog.nbind_map("Alt+Control", nog.ws_swap, direction_keys)

-- Moved this from window to workspace, because the split direction is workspace scoped and not window scoped.
nog.nbind("Alt+Plus", () => nog.ws_set_split_direction("Vertical"))
nog.nbind("Alt+Minus", () => nog.ws_set_split_direction("Horizontal"))

nog.nbind("Alt+Control+F", nog.win_toggle_floating)
nog.gbind("Alt+Control+W", nog.toggle_work_mode, "global")
nog.nbind("Alt+F", nog.ws_toggle_fullscreen)

nog.nbind_arr("Alt+Shift", nog.win_move_to_workspace, range(workspace_count))
nog.nbind_arr("Alt+Control", nog.ws_move_to_monitor, range(workspace_count))
nog.nbind_arr("Alt", nog.ws_change, range(workspace_count))

Experimentations:

As for lua bindings I would like to use mlua.

TimUntersberger commented 3 years ago

@ramirezmike @keepitsane any thoughts regarding this?

keepitsane commented 3 years ago

Probably a good idea I think, having a custom language would honestly most likely hurt long term adoption.

ramirezmike commented 3 years ago

I'm cool with it. Would also decrease the amount of things that need to be maintained moving forward too.

I do think this should be something we document how to convert configs to. I don't know how many people use nog regularly (how could you not amirite?), but it'd be good to assist them move to the new format and may reduce new issues created where the resolution is just "oh whoops, you need to use the new format".

TimUntersberger commented 3 years ago

Currently working on this in https://github.com/TimUntersberger/nog/tree/lua

TimUntersberger commented 3 years ago

The PR will be merged soon, so I am closing this now.