forked from neovide/neovide
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This cleans up the code and makes it slightly faster
- Loading branch information
1 parent
aa210c7
commit 0eef475
Showing
2 changed files
with
111 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
---@class Args | ||
---@field neovide_channel_id integer | ||
---@field register_clipboard boolean | ||
---@field register_right_click boolean | ||
|
||
---@type Args | ||
local args = ... | ||
|
||
|
||
vim.g.neovide_channel_id = args.neovide_channel_id | ||
|
||
-- Set some basic rendering options. | ||
vim.o.lazyredraw = false | ||
vim.o.termguicolors = true | ||
|
||
local function rpcnotify(method, ...) | ||
vim.rpcnotify(vim.g.neovide_channel_id, method, ...) | ||
end | ||
|
||
local function rpcrequest(method, ...) | ||
vim.rpcrequest(vim.g.neovide_channel_id, method, ...) | ||
end | ||
|
||
local function set_clipboard(register) | ||
return function(lines, regtype) | ||
rpcrequest("neovide.set_clipboard", lines) | ||
end | ||
end | ||
|
||
local function get_clipboard(register) | ||
return function() | ||
return rpcrequest("neovide.get_clipboard", register) | ||
end | ||
end | ||
|
||
if args.register_clipboard and not vim.g.neovide_no_custom_clipboard then | ||
vim.g.clipboard = { | ||
name = "neovide", | ||
copy = { | ||
["+"] = set_clipboard("+"), | ||
["*"] = set_clipboard("*"), | ||
}, | ||
paste = { | ||
["+"] = get_clipboard("+"), | ||
["*"] = get_clipboard("*"), | ||
}, | ||
cache_enabled = 0 | ||
} | ||
end | ||
|
||
if args.register_right_click then | ||
vim.api.nvim_create_user_command("NeovideRegisterRightClick", function() | ||
rpcnotify("neovide.register_right_click") | ||
end, {}) | ||
vim.api.nvim_create_user_command("NeovideUnregisterRightClick", function() | ||
rpcnotify("neovide.unregister_right_click") | ||
end, {}) | ||
end | ||
|
||
vim.api.nvim_create_autocmd({ "OptionSet" }, { | ||
pattern = "columns", | ||
once = false, | ||
nested = true, | ||
callback = function() | ||
rpcnotify("neovide.columns", tonumber(vim.v.option_new)) | ||
end | ||
}) | ||
|
||
vim.api.nvim_create_autocmd({ "OptionSet" }, { | ||
pattern = "lines", | ||
once = false, | ||
nested = true, | ||
callback = function() | ||
rpcnotify("neovide.lines", tonumber(vim.v.option_new)) | ||
end | ||
}) | ||
|
||
-- Create auto command for retrieving exit code from neovim on quit. | ||
vim.api.nvim_create_autocmd({ "VimLeavePre" }, { | ||
pattern = "*", | ||
once = true, | ||
nested = true, | ||
callback = function() | ||
rpcnotify("neovide.quit", vim.v.exiting) | ||
end | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters