add volume widget
This commit is contained in:
@@ -27,6 +27,7 @@ class Bar : public Gtk::Window
|
||||
int m_monitorId;
|
||||
WorkspaceIndicator *m_workspaceIndicator = nullptr;
|
||||
TrayWidget *m_trayWidget = nullptr;
|
||||
class VolumeWidget *m_volumeWidget = nullptr;
|
||||
|
||||
void setup_ui();
|
||||
void load_css();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
class SystemHelper
|
||||
{
|
||||
@@ -25,4 +28,18 @@ class SystemHelper
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Read an entire file into a string. Throws std::runtime_error on failure.
|
||||
static std::string read_file_to_string(const std::string &path)
|
||||
{
|
||||
std::ifstream in(path, std::ios::in | std::ios::binary);
|
||||
if (!in)
|
||||
{
|
||||
throw std::runtime_error("Failed to open file: " + path);
|
||||
}
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << in.rdbuf();
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
17
include/widgets/spacer.hpp
Normal file
17
include/widgets/spacer.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||
#include <gtkmm.h>
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
|
||||
class Spacer : public Gtk::Label
|
||||
{
|
||||
public:
|
||||
Spacer()
|
||||
{
|
||||
set_hexpand(true);
|
||||
set_text("|");
|
||||
set_name("spacer");
|
||||
}
|
||||
};
|
||||
24
include/widgets/volumeWidget.hpp
Normal file
24
include/widgets/volumeWidget.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <string>
|
||||
#include <sigc++/sigc++.h>
|
||||
|
||||
class VolumeWidget : public Gtk::Box
|
||||
{
|
||||
public:
|
||||
VolumeWidget();
|
||||
virtual ~VolumeWidget();
|
||||
|
||||
// Refresh displayed volume from the system
|
||||
void update();
|
||||
|
||||
protected:
|
||||
// timeout handler for periodic polling; return true to keep polling
|
||||
bool on_timeout();
|
||||
|
||||
private:
|
||||
Gtk::Label m_label;
|
||||
Glib::RefPtr<Gtk::GestureClick> m_click;
|
||||
sigc::connection m_timeoutConn;
|
||||
};
|
||||
Reference in New Issue
Block a user