Skip to content

Commit

Permalink
feat: konsole plugin with fullscreen mode management
Browse files Browse the repository at this point in the history
  • Loading branch information
ekorchmar committed Aug 19, 2024
1 parent 29b292b commit d598415
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions lua/zen-mode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions lua/zen-mode/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d598415

Please sign in to comment.