major status improvements

This commit is contained in:
vrd
2026-07-30 11:54:49 +03:00
committed by Venelin Dechkov
parent 5b8797bccd
commit 0e5b9f1473
7 changed files with 135 additions and 18 deletions
+118 -17
View File
@@ -6,8 +6,13 @@
#include <chrono>
#include <filesystem>
#include <cppipe/commands.hpp>
#include <X11/X.h>
// #include "vene.h"
#include "vene_env.h"
extern "C"
{
#include "slstatus/slstatus.h"
}
using namespace std;
using namespace std::chrono;
@@ -22,18 +27,62 @@ namespace
time_point<system_clock> next_update;
bool has_child;
Proc child;
Proc browser = {.pid = 0};
}
extern "C"
{
// from dwm
struct Monitor;
typedef struct {
const char *symbol;
void (*arrange)(Monitor *);
} Layout;
struct Client {
char name[256];
float mina, maxa;
int x, y, w, h;
int oldx, oldy, oldw, oldh;
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
Client *next;
Client *snext;
Monitor *mon;
Window win;
};
struct Monitor {
char ltsymbol[16];
float mfact;
int nmaster;
int num;
int by; /* bar geometry */
int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */
unsigned int seltags;
unsigned int sellt;
unsigned int tagset[2];
int showbar;
int topbar;
Client *clients;
Client *sel;
Client *stack;
Monitor *next;
Window barwin;
const Layout *lt[2];
};
typedef union {
int i;
unsigned int ui;
float f;
const void *v;
} Arg;
extern Monitor *selmon;
void updatestatus();
void view(const Arg* arg);
// end
@@ -46,9 +95,6 @@ extern "C"
strcpy(SCREEN_CAPS_DIR, HOME);
strcat(SCREEN_CAPS_DIR, "/screen_caps/");
// Signal handlers
// signal(SIGRTMIN, goto_tag);
// strcpy(BOOKMARK_DIR, HOME);
// strcat(BOOKMARK_DIR, "/notes/bookmarks/web");
@@ -65,12 +111,58 @@ extern "C"
static string new_stat;
new_stat.clear();
// Net
string eth_state;
ifstream("/sys/class/net/eth0/operstate") >> eth_state;
if(eth_state == "up")
new_stat += "🌐 ";
try
{
// Net
for(const auto& dir_entry: fs::directory_iterator("/sys/class/net"))
{
string interface_state;
string interface = dir_entry.path().filename();
switch(interface[0])
{
case 'e': // if the name begins with 'e' its ethernet
ifstream(dir_entry.path() / "operstate") >> interface_state;
if(interface_state == "up")
new_stat += "🌐 ";
break;
case 'w': // 'w' means wifi
ifstream(dir_entry.path() / "operstate") >> interface_state;
if(interface_state == "up")
{
new_stat += "🛜";
if(const char* ssid = wifi_essid(interface.c_str()); ssid)
new_stat += ssid;
new_stat += ' ';
if(const char* perc = wifi_perc(interface.c_str()); perc)
{
new_stat += perc;
new_stat += "% ";
}
}
break;
}
}
// Battery
string charge, state;
ifstream("/sys/class/power_supply/BAT0/capacity") >> charge;
ifstream("/sys/class/power_supply/BAT0/status") >> state;
const char* remaining = "";
if(state == "Discharging")
{
new_stat += "🔋";
remaining = battery_remaining("BAT0");
}
else
new_stat += "🔌";
new_stat += charge;
new_stat += "% ";
new_stat += remaining;
new_stat += ' ';
}
catch(...){ cerr << "EXCEPT\n"; }
// Volume
string amix_out = $(Cmd("amixer", "get", AUDIO_DEV));
@@ -109,6 +201,9 @@ extern "C"
time_point<system_clock> now = system_clock::now();
if(has_child && check_exited(child))
{
// Clean up all zombies
while (waitpid(-1, nullptr, WNOHANG) > 0);
has_child = false;
updatestatus();
next_update = now + 10s;
@@ -122,16 +217,22 @@ extern "C"
void vene_browser(const Arg* arg)
{
if( browser.pid == 0 || check_exited(browser) ) // not running
{
browser = Cmd(BROWSER).detach();
bool browser_tag_used = false;
for(Client* c = selmon->clients; c; c = c->next)
if(c->tags & 1<<8)
{
browser_tag_used = true;
break;
}
// Clean up all zombies
while (waitpid(-1, nullptr, WNOHANG) > 0);
}
else // running, view it
// if( browser_tag_used ) // browser tag is empty, start browser
{
view(arg);
}
// else // view browser tag
{
// Cmd(BROWSER).detach();
}
}
@@ -187,7 +288,7 @@ extern "C"
void vene_toggle_vol(const Arg*)
{
Cmd toggle_vol("amixer", "-q", "set", AUDIO_DEV, "toggle");
Cmd toggle_vol("amixer", "-q", "-Dpulse", "set", AUDIO_DEV, "toggle");
child = toggle_vol.detach();
has_child = true;
}