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
+3
View File
@@ -0,0 +1,3 @@
[submodule "slstatus"]
path = slstatus
url = https://gitlab.com/venelin98/slstatus.git
+6
View File
@@ -68,6 +68,8 @@ static const Layout layouts[] = {
// static const char* dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; // static const char* dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char* dmenucmd[] = { "dmenu_run", NULL }; static const char* dmenucmd[] = { "dmenu_run", NULL };
static const char* termcmd[] = { "st", NULL }; static const char* termcmd[] = { "st", NULL };
static const char* bright_up[] = { "brightnessctl", "s", "-q", "3%+", NULL };
static const char* bright_down[] = { "brightnessctl", "s", "-q", "3%-", NULL };
static const char* screenshot [] = { "scrot", "-s", SCREEN_CAPS_DIR, NULL }; static const char* screenshot [] = { "scrot", "-s", SCREEN_CAPS_DIR, NULL };
static void webbookmark(const Arg* arg){ static void webbookmark(const Arg* arg){
@@ -83,6 +85,10 @@ static const Key keys[] = {
{ 0, XF86XK_AudioRaiseVolume, vene_inc_vol, {0 } }, { 0, XF86XK_AudioRaiseVolume, vene_inc_vol, {0 } },
{ 0, XF86XK_AudioLowerVolume, vene_dec_vol, {0 } }, { 0, XF86XK_AudioLowerVolume, vene_dec_vol, {0 } },
{ 0, XF86XK_AudioMute, vene_toggle_vol, {0 } }, { 0, XF86XK_AudioMute, vene_toggle_vol, {0 } },
#if HAS_SW_BACKLIGHT
{ 0, XF86XK_MonBrightnessUp, spawn, {.v = bright_up } },
{ 0, XF86XK_MonBrightnessDown,spawn, {.v = bright_down } },
#endif
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_s, togglebar, {0} }, { MODKEY, XK_s, togglebar, {0} },
Executable
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -262,7 +262,7 @@ static Cur *cursor[CurLast];
static Clr **scheme; static Clr **scheme;
static Display *dpy; static Display *dpy;
static Drw *drw; static Drw *drw;
static Monitor *mons, *selmon; Monitor *mons, *selmon;
static Window root, wmcheckwin; static Window root, wmcheckwin;
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
Submodule
+1
Submodule slstatus added at f68f49273e
+6
View File
@@ -35,3 +35,9 @@ ecalloc(size_t nmemb, size_t size)
die("calloc:"); die("calloc:");
return p; return p;
} }
#include "slstatus/util.c"
// slstatus.c:
char buf[1024];
#include "slstatus/components/wifi.c"
#include "slstatus/components/battery.c"
+115 -14
View File
@@ -6,8 +6,13 @@
#include <chrono> #include <chrono>
#include <filesystem> #include <filesystem>
#include <cppipe/commands.hpp> #include <cppipe/commands.hpp>
#include <X11/X.h>
// #include "vene.h" // #include "vene.h"
#include "vene_env.h" #include "vene_env.h"
extern "C"
{
#include "slstatus/slstatus.h"
}
using namespace std; using namespace std;
using namespace std::chrono; using namespace std::chrono;
@@ -22,18 +27,62 @@ namespace
time_point<system_clock> next_update; time_point<system_clock> next_update;
bool has_child; bool has_child;
Proc child; Proc child;
Proc browser = {.pid = 0};
} }
extern "C" extern "C"
{ {
// from dwm // 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 { typedef union {
int i; int i;
unsigned int ui; unsigned int ui;
float f; float f;
const void *v; const void *v;
} Arg; } Arg;
extern Monitor *selmon;
void updatestatus(); void updatestatus();
void view(const Arg* arg); void view(const Arg* arg);
// end // end
@@ -46,9 +95,6 @@ extern "C"
strcpy(SCREEN_CAPS_DIR, HOME); strcpy(SCREEN_CAPS_DIR, HOME);
strcat(SCREEN_CAPS_DIR, "/screen_caps/"); strcat(SCREEN_CAPS_DIR, "/screen_caps/");
// Signal handlers
// signal(SIGRTMIN, goto_tag);
// strcpy(BOOKMARK_DIR, HOME); // strcpy(BOOKMARK_DIR, HOME);
// strcat(BOOKMARK_DIR, "/notes/bookmarks/web"); // strcat(BOOKMARK_DIR, "/notes/bookmarks/web");
@@ -65,12 +111,58 @@ extern "C"
static string new_stat; static string new_stat;
new_stat.clear(); new_stat.clear();
try
{
// Net // Net
string eth_state; for(const auto& dir_entry: fs::directory_iterator("/sys/class/net"))
ifstream("/sys/class/net/eth0/operstate") >> eth_state; {
if(eth_state == "up") 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 += "🌐 "; 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 // Volume
string amix_out = $(Cmd("amixer", "get", AUDIO_DEV)); string amix_out = $(Cmd("amixer", "get", AUDIO_DEV));
@@ -109,6 +201,9 @@ extern "C"
time_point<system_clock> now = system_clock::now(); time_point<system_clock> now = system_clock::now();
if(has_child && check_exited(child)) if(has_child && check_exited(child))
{ {
// Clean up all zombies
while (waitpid(-1, nullptr, WNOHANG) > 0);
has_child = false; has_child = false;
updatestatus(); updatestatus();
next_update = now + 10s; next_update = now + 10s;
@@ -122,16 +217,22 @@ extern "C"
void vene_browser(const Arg* arg) void vene_browser(const Arg* arg)
{ {
if( browser.pid == 0 || check_exited(browser) ) // not running bool browser_tag_used = false;
for(Client* c = selmon->clients; c; c = c->next)
if(c->tags & 1<<8)
{ {
browser = Cmd(BROWSER).detach(); 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); view(arg);
}
// else // view browser tag
{
// Cmd(BROWSER).detach();
} }
} }
@@ -187,7 +288,7 @@ extern "C"
void vene_toggle_vol(const Arg*) 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(); child = toggle_vol.detach();
has_child = true; has_child = true;
} }