Skip to content

Commit b65a7cf

Browse files
committed
Match background with system appearance on Windows
On start-up only
1 parent e3fa500 commit b65a7cf

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lua/daybreak.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
local gdbus = require('gdbus')
22
local macos = require('macos')
3+
local windows = require('windows')
34

45
local M = {}
56

67
function M.setup(_)
78
if vim.fn.has('osx') == 1 then
89
macos.setup()
10+
elseif vim.fn.has('win32') == 1 or vim.fn.has('win64') == 1 then
11+
windows.setup()
912
elseif vim.fn.executable('gdbus') == 1 then
1013
gdbus.setup()
1114
end

lua/windows.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
local M = {}
2+
3+
function M.setup()
4+
local reg_cmd = 'reg query'
5+
.. ' HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize'
6+
.. ' /v AppsUseLightTheme'
7+
local reg_stdout = io.popen(reg_cmd)
8+
if reg_stdout == nil then
9+
print('can\'t execute reg')
10+
return
11+
end
12+
local stdout_str = reg_stdout:read('*a')
13+
local exit_success = reg_stdout:close()
14+
if exit_success ~= true then
15+
print('reg command failed')
16+
return
17+
end
18+
local value = stdout_str:match('AppsUseLightTheme%s+REG_DWORD%s+0x(%d+)')
19+
if value == nil then
20+
print('unrecognized registry value')
21+
return
22+
end
23+
vim.opt.background = value == '1' and 'light' or 'dark'
24+
end
25+
26+
return M

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Using any other plugin manager add `raindev/daybreak.nvim` and load the plugin w
1717
- [ ] macOS
1818
- [ ] windows
1919
2. Event based, no polling.
20-
3. Support Linux, macOS and Windows (planned).
20+
3. Support Linux, macOS and Windows.
2121
4. Zero configuration.

0 commit comments

Comments
 (0)