From d598415f44915109120e8de81ba01e735e2f216c Mon Sep 17 00:00:00 2001 From: Eduard Korchmar Date: Tue, 20 Aug 2024 00:24:54 +0200 Subject: [PATCH] feat: konsole plugin with fullscreen mode management --- README.md | 12 +++++++++ lua/zen-mode/config.lua | 11 ++++++++ lua/zen-mode/plugins.lua | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/README.md b/README.md index 4ac77b3..5402340 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Distraction-free coding for Neovim >= 0.5 - increase [Alacritty](https://alacritty.org/) font-size - increase [wezterm](https://wezfurlong.org/wezterm/) font-size - increase [Neovide](https://neovide.dev/) scale factor and disable animations + - switch to a preconfigured profile in [Konsole](https://konsole.kde.org/) - **Zen Mode** is automatically closed when a new non-floating window is opened - works well with plugins like [Telescope](https://github.com/nvim-telescope/telescope.nvim) to open a new buffer inside the Zen window - close the Zen window with `:ZenMode`, `:close` or `:quit` @@ -130,6 +131,17 @@ Install the plugin with your preferred package manager: neovide_cursor_vfx_mode = "", } }, + -- this will change the profile in Konsole when in Zen mode and/or make it fullscreen + konsole = { + enabled = true, + -- this will turn the window borderless fullscreen on enter and back to + -- normal on exit + fullscreen = true, + -- when set to true, this will switch to the profile called "Zen" when + -- entering Zen mode and back to the original profile on exit; can be set + -- to a string to use a specific profile instead + profile = false, + }, }, -- callback where you can add custom code when the Zen window opens on_open = function(win) diff --git a/lua/zen-mode/config.lua b/lua/zen-mode/config.lua index 3a862e6..3094394 100644 --- a/lua/zen-mode/config.lua +++ b/lua/zen-mode/config.lua @@ -75,6 +75,17 @@ local defaults = { neovide_cursor_vfx_mode = "", }, }, + -- this will change the profile in Konsole when in Zen mode and/or make it fullscreen + konsole = { + enabled = true, + -- this will turn the window borderless fullscreen on enter and back to + -- normal on exit + fullscreen = true, + -- when set to true, this will switch to the profile called "Zen" when + -- entering Zen mode and back to the original profile on exit; can be set + -- to a string to use a specific profile instead + profile = false, + }, }, -- callback where you can add custom code when the zen window opens on_open = function(_win) end, diff --git a/lua/zen-mode/plugins.lua b/lua/zen-mode/plugins.lua index 21eb4c9..8866cee 100644 --- a/lua/zen-mode/plugins.lua +++ b/lua/zen-mode/plugins.lua @@ -150,6 +150,60 @@ function M.neovide(state, disable, opts) end end +-- Switches konsole to "Zen" profile +function M.konsole(state, disable, opts) + local service = vim.env.KONSOLE_DBUS_SERVICE + if not service then + return + end + + local session = vim.env.KONSOLE_DBUS_SESSION + if opts.profile and not session then + return + end + + local exec + if opts.executable then + exec = opts.executable + else + for _, bin in ipairs({ "qdbus6", "qdbus", "qdbus5" }) do + if vim.fn.executable(bin) then + exec = bin + break + end + end + end + if not exec then + return + end + + local fs = "%s %s /konsole/MainWindow_1 viewFullScreen %s" + local pf = "Zen" + local pf_read = "%s %s %s profile" + local pf_write = "%s %s %s setProfile %s" + if disable then + if opts.fullscreen then + vim.fn.system(string.format(fs, exec, service, "true")) + end + if opts.profile then + if opts.profile ~= true then + pf = opts.profile + end + state.pf = vim.fn.system(string.format(pf_read, exec, service, session)) + vim.fn.system(string.format(pf_write, exec, service, session, pf)) + end + return + else + if opts.fullscreen then + vim.fn.system(string.format(fs, exec, service, "false")) + end + if opts.profile then + vim.fn.system(string.format(pf_write, exec, service, session, state.pf)) + end + return + end +end + function M.diagnostics(state, disable) if disable then vim.diagnostic.disable(0)