Compile and load .scss directly with libsass (#76)

Even though an scss file is present, it needs to be converted manually and only the
CSS file is parsed. This pull request sets out to fix that.

there is preliminary scss support using libsass now (libsass is technically "deprecated" but there seems to be no other
c/c++ library for converting scss to css)
This commit is contained in:
Sivecano 2024-03-13 01:21:49 +01:00 committed by GitHub
parent fbf25048ff
commit 74a04abd53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 6 deletions

View file

@ -13,6 +13,7 @@ My personal blazingly fast and efficient status bar + widgets, in case anyone fi
- gtk-layer-shell
- PulseAudio server (PipeWire works too!)
- pamixer
- libsass
- meson, gcc/clang, ninja
## Building and installation (Manually)

View file

@ -28,6 +28,9 @@ gtk_layer_shell = dependency('gtk-layer-shell-0')
pulse = dependency('libpulse')
sass = dependency('libsass')
headers = [
'src/Common.h',
'src/Log.h',
@ -58,7 +61,7 @@ sources = [
'src/SNI.cpp',
]
dependencies = [gtk, gtk_layer_shell, pulse, wayland_client ]
dependencies = [gtk, gtk_layer_shell, pulse, wayland_client, sass]
if get_option('WithHyprland')
add_global_arguments('-DWITH_HYPRLAND', language: 'cpp')

View file

@ -5,6 +5,8 @@
#include <array>
#include <fstream>
#include <sass.h>
namespace CSS
{
static GtkCssProvider* sProvider;
@ -58,21 +60,49 @@ namespace CSS
GError* err = nullptr;
for (auto& dir : locations)
{
std::string file = dir + "/style.css";
std::string file = dir + "/style.scss";
bool scss_suceeded = false;
if (!std::ifstream(file).is_open())
if (std::ifstream(file).is_open())
{
LOG("Info: No CSS found in " << dir);
continue;
Sass_File_Context* ctx = sass_make_file_context(file.c_str());
Sass_Context* ctxout = sass_file_context_get_context(ctx);
sass_compile_file_context(ctx);
if(sass_context_get_error_status(ctxout))
{
LOG("Error Compiling SCSS: " << sass_context_get_error_message(ctxout));
}
else
{
std::string data = sass_context_get_output_string(ctxout);
gtk_css_provider_load_from_data(sProvider, data.c_str(), data.length(), &err);
scss_suceeded = true;
}
sass_delete_file_context(ctx);
}
gtk_css_provider_load_from_path(sProvider, file.c_str(), &err);
if (!scss_suceeded)
{
LOG("Info: couldn't load SCSS from " << dir);
file = dir + "/style.css";
if (!std::ifstream(file).is_open())
{
LOG("Info: No CSS found in " << dir);
continue;
}
gtk_css_provider_load_from_path(sProvider, file.c_str(), &err);
}
if (!err)
{
LOG("CSS found and loaded successfully!");
return;
}
LOG("Warning: Failed loading config for " << dir << ", trying next one!");
// Log any errors
LOG(err->message);