Swayimg image viewer setup with dynamic niri noctalia theming
@V0lcaneR
·
2026-05-01
·
via CachyOS Forum - Latest posts
Well, I needed a basic default image viewer for my niri + noctalia install. So spent the last couple of days setting up a swayimg template that is compatible with noctalias user templates. I will be talking about setting this up here. I will NOT be talking about setting up keybinds right now as I haven’t gotten to that part yet. Before that though a little about my niche use-case: I use noctalias wallpaper colors (Faithful method) + scheduled wallpaper changes once per hour. This results in me wanting live theme reloads on almost all of my software for cohesion since I have a habit of leaving a lot of software open. If you don’t need the live theme reload then just copy the setColors.lua file as your init.lua and modify it to your hearts content. (also make sure that the noctalia user templates targets your init file) With that out of the way lets begin: The swayimg config file is init.lua and uses functions to set configuration variables. The software itself has 3 modes “viewer”, “gallery” and “slideshow”. Each of these has its own config functions. For the purpose of theming we care about the on_signal config functions and the dofile lua function. The on_signal function is called when swayimg recieves an external signal from the system. In this case we will be using the “USR1” signal, but “USR2” is also supported by the function. The dofile function accepts a single parameter which is a path to another lua file, it finds it and runs it. It requires absolute path as it couldn’t find the file when i used the ~ shortcut. The purpose of on_signal is to act as a hook to use to tell swayimg to reload its theme. We need the dofile function to load a separate file that will be the template target. This is because swayimg keeps a copy of the init file in memory and does not refresh it. So to start you want to navigate to one of the directories listed in the config . I used option 2 personally. You want to create 2 files: init.lua and setColors_temlpate.lua ( setColors.lua will be generated by noctalia) init.lua : swayimg.text.set_size(24) swayimg.viewer.set_default_scale("width") swayimg.viewer.enable_loop("true") -- This section sets the colors path="<your_path>/setColors.lua" dofile(path) swayimg.viewer.on_signal("USR1", function() dofile(path) end) swayimg.slideshow.on_signal("USR1", function() dofile(path) end) swayimg.gallery.on_signal("USR1", function() dofile(path) end) setColors_temlpate.lua : swayimg.text.set_foreground(0xdd{{colors.on_surface.default.hex_stripped}}) swayimg.text.set_background(0xaa{{colors.surface.default.hex_stripped}}) swayimg.text.set_shadow(0xff{{colors.shadow.default.hex_stripped}}) swayimg.viewer.set_mark_color(0xee{{colors.primary.default.hex_stripped}}) swayimg.viewer.set_window_background(0xaa{{colors.surface.default.hex_stripped}}) -- you can customize the transparency chessboard, keep both commented for the default chessboard style. swayimg.viewer.set_image_background(0xcc{{colors.surface_variant.default.hex_stripped}}) -- swayimg.viewer.set_image_chessboard(25, 0xee{{colors.tertiary.default.hex_stripped | set_lightness 10 | set_saturation 10}}, 0xee{{colors.tertiary.default.hex_stripped | set_lightness 30 | set_saturation 10}}) swayimg.gallery.set_mark_color(0xee{{colors.primary.default.hex_stripped}}) swayimg.gallery.set_border_color(0xee{{colors.primary.default.hex_stripped}}) swayimg.gallery.set_selected_color(0x11{{colors.secondary.default.hex_stripped}}) swayimg.gallery.set_unselected_color(0x11{{colors.surface.default.hex_stripped}}) swayimg.gallery.set_window_color(0xaa{{colors.surface.default.hex_stripped}}) swayimg.slideshow.set_mark_color(0xee{{colors.primary.default.hex_stripped}}) swayimg.slideshow.set_window_background(0xaa{{colors.surface.default.hex_stripped}}) swayimg.slideshow.set_image_background(0xcc{{colors.surface_variant.default.hex_stripped}}) -- swayimg.slideshow.set_image_chessboard(25, 0xee{{colors.tertiary.default.hex_stripped | set_lightness 10 | set_saturation 10}}, 0xee{{colors.tertiary.default.hex_stripped | set_lightness 30 | set_saturation 10}}) -- swayimg.text.set_status("Ctrl+Alt+R 0x99{{colors.surface.default.hex_stripped}}") Then add the following to your user-templates.toml (if the file doesn’t exist you need to enable user templates in noctalia first): [templates.swayimg] input_path = "<your_path>/setColors_template.lua" output_path = "<your_path>/setColors.lua" post_hook = "kill -s USR1 $(pidof swayimg)" The horrifying kill command just sends the USR1 signal to every pid of swayimg (this works with multiple instances too) Lastly you need to regenerate a color scheme to generate the setColors.lua file and you are done! If you dont care about live theming then just add whatever swayimg configuration you want to the setColors_template.lua file, then modify the user-templates.toml by redirecting the output_path to init.lua and then remove the post_hook. This will reload the theme when you restart swayimg. I am new to this so I probably made a bunch of mistakes here. I’d appreciate any feedback you have and I hope this helped!
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。