Explorar el Código

add light/darkmode support to neovim

Noah Vogt hace 14 horas
padre
commit
41b8c02230

+ 2 - 2
dot-config/hypr/hyprland.conf

@@ -80,8 +80,8 @@ decoration {
     rounding_power = 2
 
     # Change transparency of focused and unfocused windows
-    active_opacity = 0.85
-    inactive_opacity = 0.85
+    active_opacity = 0.9
+    inactive_opacity = 0.9
 
     shadow {
         enabled = true

+ 2 - 0
dot-config/hypr/scripts/toggle-theme.sh

@@ -19,3 +19,5 @@ fi
 
 # Send SIGUSR2 to Waybar so it dynamically reloads style.css (which now imports theme.css)
 killall -SIGUSR2 waybar
+# same thing for for neovim
+killall -SIGUSR1 nvim

+ 6 - 6
dot-config/nvim/init.lua

@@ -16,10 +16,7 @@ require('options')
 -- 3. Load plugins (lazy.nvim)
 require('plugins')
 
--- 4. Load Theme (Important for Treesitter highlight groups)
-require('theme')
-
--- 5. Load Plugin configurations (some are still in vimscript)
+-- 4. Load Plugin configurations (some are still in vimscript)
 local plug_confs = {
   'emmet', 'ctrlp', 'sneak', 'airline',
   'startify', 'wilder', 'vcoolor', 'better-whitespace', 'vimspector'
@@ -28,7 +25,7 @@ for _, conf in ipairs(plug_confs) do
   vim.cmd('source $XDG_CONFIG_HOME/nvim/plug-conf/' .. conf .. '.vim')
 end
 
--- 6. Load Lua-specific configurations
+-- 5. Load Lua-specific configurations
 require('treesitter')
 require('lsp')
 require('nvim-tree-conf')
@@ -39,9 +36,12 @@ require('indent-blankline')
 require('whichkey')
 require('colorizer').setup()
 
--- 7. Load keybinds and autocommands
+-- 6. Load keybinds and autocommands
 require('keymaps')
 require('autocmds')
 
+-- 7. Load Theme last to ensure it has the final word on background/colors
+require('theme')
+
 -- Enable intelligent indentation
 vim.cmd('filetype plugin indent on')

+ 9 - 0
dot-config/nvim/lua/autocmds.lua

@@ -159,3 +159,12 @@ autocmd("FileType", {
   end,
 })
 
+-- Sync theme on focus
+augroup("theme_sync", { clear = true })
+autocmd("FocusGained", {
+  group = "theme_sync",
+  callback = function()
+    require('theme').sync_theme()
+  end,
+})
+

+ 69 - 26
dot-config/nvim/lua/theme.lua

@@ -1,26 +1,69 @@
-require('onedark').setup {
-    style = 'cool', -- 'cool' or 'vibrant' are usually better for TS
-    transparent = false,
-    term_colors = true,
-    -- Remove overrides to use theme defaults
-    code_style = {
-        comments = 'italic',
-    },
-}
-require('onedark').load()
-
--- Force colors for diagnostics and spell check underlines ONLY
-vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
-vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn',  { undercurl = true, sp = '#ff8800' })
-vim.api.nvim_set_hl(0, 'SpellBad',   { undercurl = true, sp = '#ffff00' })
-vim.api.nvim_set_hl(0, 'SpellCap',   { undercurl = true, sp = '#ffff00' })
-vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
-vim.api.nvim_set_hl(0, 'SpellRare',  { undercurl = true, sp = '#ffff00' })
-
--- GitSigns
-vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = '#98c379', bg = '#2e3f34' })
-vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = '#e5c07b', bg = '#3e3d32' })
-vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = '#e06c75', bg = '#3f2e2e' })
-
-vim.g.airline_theme = 'onedark'
-vim.opt.background = 'dark'
+local M = {}
+
+function M.sync_theme()
+    -- Use vim.fn.system for more reliable command execution in Neovim
+    local result = vim.fn.system("gsettings get org.gnome.desktop.interface color-scheme")
+
+    -- Check for 'light' anywhere in the output
+    if result:match("light") then
+        vim.o.background = "light"
+        require('onedark').setup {
+            style = 'light',
+            transparent = false,
+            term_colors = true,
+            code_style = { comments = 'italic' },
+        }
+        require('onedark').load()
+
+        -- Override GitSigns for light mode
+        vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = '#2c7a36', bg = '#d9f2da' })
+        vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = '#a68a0d', bg = '#fbf0c9' })
+        vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = '#a62621', bg = '#f9dada' })
+    else
+        vim.o.background = "dark"
+        require('onedark').setup {
+            style = 'cool',
+            transparent = false,
+            term_colors = true,
+            code_style = { comments = 'italic' },
+        }
+        require('onedark').load()
+
+        -- Override GitSigns for dark mode
+        vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = '#98c379', bg = '#2e3f34' })
+        vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = '#e5c07b', bg = '#3e3d32' })
+        vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = '#e06c75', bg = '#3f2e2e' })
+    end
+
+    -- Force colors for diagnostics and spell check underlines
+    vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
+    vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn',  { undercurl = true, sp = '#ff8800' })
+    vim.api.nvim_set_hl(0, 'SpellBad',   { undercurl = true, sp = '#ffff00' })
+    vim.api.nvim_set_hl(0, 'SpellCap',   { undercurl = true, sp = '#ffff00' })
+    vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
+    vim.api.nvim_set_hl(0, 'SpellRare',  { undercurl = true, sp = '#ffff00' })
+
+    -- Force airline to refresh
+    vim.g.airline_theme = 'onedark'
+    if vim.fn.exists(':AirlineTheme') == 2 then
+        vim.cmd('AirlineTheme onedark')
+    end
+
+    -- Force a full redraw to fix background issues in some terminals
+    vim.cmd('redraw!')
+end
+
+-- Initial sync on load
+M.sync_theme()
+
+-- Set up signal handler for SIGUSR1 to trigger a theme sync
+local signal = vim.loop.new_signal()
+if signal then
+    signal:start("sigusr1", function()
+        vim.schedule(function()
+            M.sync_theme()
+        end)
+    end)
+end
+
+return M