major status improvements
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
[submodule "slstatus"]
|
||||
path = slstatus
|
||||
url = https://gitlab.com/venelin98/slstatus.git
|
||||
@@ -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", 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 void webbookmark(const Arg* arg){
|
||||
@@ -83,6 +85,10 @@ static const Key keys[] = {
|
||||
{ 0, XF86XK_AudioRaiseVolume, vene_inc_vol, {0 } },
|
||||
{ 0, XF86XK_AudioLowerVolume, vene_dec_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|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||
{ MODKEY, XK_s, togglebar, {0} },
|
||||
|
||||
@@ -262,7 +262,7 @@ static Cur *cursor[CurLast];
|
||||
static Clr **scheme;
|
||||
static Display *dpy;
|
||||
static Drw *drw;
|
||||
static Monitor *mons, *selmon;
|
||||
Monitor *mons, *selmon;
|
||||
static Window root, wmcheckwin;
|
||||
|
||||
/* configuration, allows nested code to access above variables */
|
||||
|
||||
Submodule
+1
Submodule slstatus added at f68f49273e
@@ -35,3 +35,9 @@ ecalloc(size_t nmemb, size_t size)
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
||||
#include "slstatus/util.c"
|
||||
// slstatus.c:
|
||||
char buf[1024];
|
||||
#include "slstatus/components/wifi.c"
|
||||
#include "slstatus/components/battery.c"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user