mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-21 18:52:49 +00:00
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:
parent
fbf25048ff
commit
74a04abd53
3 changed files with 40 additions and 6 deletions
|
@ -13,6 +13,7 @@ My personal blazingly fast and efficient status bar + widgets, in case anyone fi
|
||||||
- gtk-layer-shell
|
- gtk-layer-shell
|
||||||
- PulseAudio server (PipeWire works too!)
|
- PulseAudio server (PipeWire works too!)
|
||||||
- pamixer
|
- pamixer
|
||||||
|
- libsass
|
||||||
- meson, gcc/clang, ninja
|
- meson, gcc/clang, ninja
|
||||||
|
|
||||||
## Building and installation (Manually)
|
## Building and installation (Manually)
|
||||||
|
|
|
@ -28,6 +28,9 @@ gtk_layer_shell = dependency('gtk-layer-shell-0')
|
||||||
|
|
||||||
pulse = dependency('libpulse')
|
pulse = dependency('libpulse')
|
||||||
|
|
||||||
|
sass = dependency('libsass')
|
||||||
|
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
'src/Common.h',
|
'src/Common.h',
|
||||||
'src/Log.h',
|
'src/Log.h',
|
||||||
|
@ -58,7 +61,7 @@ sources = [
|
||||||
'src/SNI.cpp',
|
'src/SNI.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies = [gtk, gtk_layer_shell, pulse, wayland_client ]
|
dependencies = [gtk, gtk_layer_shell, pulse, wayland_client, sass]
|
||||||
|
|
||||||
if get_option('WithHyprland')
|
if get_option('WithHyprland')
|
||||||
add_global_arguments('-DWITH_HYPRLAND', language: 'cpp')
|
add_global_arguments('-DWITH_HYPRLAND', language: 'cpp')
|
||||||
|
|
40
src/CSS.cpp
40
src/CSS.cpp
|
@ -5,6 +5,8 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <sass.h>
|
||||||
|
|
||||||
namespace CSS
|
namespace CSS
|
||||||
{
|
{
|
||||||
static GtkCssProvider* sProvider;
|
static GtkCssProvider* sProvider;
|
||||||
|
@ -58,21 +60,49 @@ namespace CSS
|
||||||
GError* err = nullptr;
|
GError* err = nullptr;
|
||||||
for (auto& dir : locations)
|
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);
|
Sass_File_Context* ctx = sass_make_file_context(file.c_str());
|
||||||
continue;
|
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)
|
if (!err)
|
||||||
{
|
{
|
||||||
LOG("CSS found and loaded successfully!");
|
LOG("CSS found and loaded successfully!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG("Warning: Failed loading config for " << dir << ", trying next one!");
|
LOG("Warning: Failed loading config for " << dir << ", trying next one!");
|
||||||
// Log any errors
|
// Log any errors
|
||||||
LOG(err->message);
|
LOG(err->message);
|
||||||
|
|
Loading…
Reference in a new issue