mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 22:52:30 +02:00
Merge pull request #2852 from dpayne/add_css_reload
Adding css reloader
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
|
||||
#include "bar.hpp"
|
||||
#include "config.hpp"
|
||||
#include "util/css_reload_helper.hpp"
|
||||
#include "util/portal.hpp"
|
||||
|
||||
struct zwlr_layer_shell_v1;
|
||||
@ -55,6 +56,8 @@ class Client {
|
||||
Glib::RefPtr<Gtk::CssProvider> css_provider_;
|
||||
std::unique_ptr<Portal> portal;
|
||||
std::list<struct waybar_output> outputs_;
|
||||
std::unique_ptr<CssReloadHelper> m_cssReloadHelper;
|
||||
std::string m_cssFile;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
47
include/util/css_reload_helper.hpp
Normal file
47
include/util/css_reload_helper.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "giomm/file.h"
|
||||
#include "giomm/filemonitor.h"
|
||||
#include "glibmm/refptr.h"
|
||||
|
||||
struct pollfd;
|
||||
|
||||
namespace waybar {
|
||||
class CssReloadHelper {
|
||||
public:
|
||||
CssReloadHelper(std::string cssFile, std::function<void()> callback);
|
||||
|
||||
virtual void monitorChanges();
|
||||
|
||||
protected:
|
||||
std::vector<std::string> parseImports(const std::string& cssFile);
|
||||
|
||||
void parseImports(const std::string& cssFile, std::unordered_map<std::string, bool>& imports);
|
||||
|
||||
void watchFiles(const std::vector<std::string>& files);
|
||||
|
||||
bool handleInotifyEvents(int fd);
|
||||
|
||||
bool watch(int inotifyFd, pollfd* pollFd);
|
||||
|
||||
virtual std::string getFileContents(const std::string& filename);
|
||||
|
||||
virtual std::string findPath(const std::string& filename);
|
||||
|
||||
void handleFileChange(Glib::RefPtr<Gio::File> const& file,
|
||||
Glib::RefPtr<Gio::File> const& other_type,
|
||||
Gio::FileMonitorEvent event_type);
|
||||
|
||||
private:
|
||||
std::string m_cssFile;
|
||||
|
||||
std::function<void()> m_callback;
|
||||
|
||||
std::vector<std::tuple<Glib::RefPtr<Gio::FileMonitor>>> m_fileMonitors;
|
||||
};
|
||||
} // namespace waybar
|
Reference in New Issue
Block a user