#include #include #include #include #include #include #include // #include "vene.h" #include "vene_env.h" using namespace std; using namespace std::chrono; using namespace std::chrono_literals; char* HOME; char SCREEN_CAPS_DIR[64]; namespace { time_point next_update; bool has_child; Proc child; } extern "C" { // from dwm typedef union { int i; unsigned int ui; float f; const void *v; } Arg; void updatestatus(); // end void vene_setup() { // Init vars HOME = getenv("HOME"); 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"); // sprintf(OPEN_BOOKMARK_CMD, "xdg-open $(dmenumap ~/notes/bookmarks/web/$(ls %s | dmenu "DMENU_OPTS") "DMENU_OPTS")", BOOKMARK_DIR); // strcpy(OPEN_BOOKMARK_CMD, "xdg-open $(dmenumap "DMENU_OPTS" ~/notes/bookmarks/web/$(ls "); // strcat(OPEN_BOOKMARK_CMD, BOOKMARK_DIR); // strcat(OPEN_BOOKMARK_CMD, " | dmenu "DMENU_OPTS); } void vene_updatestatus(char status[]) { using std::string; 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 += "🌐 "; // Volume string amix_out = $(Cmd("amixer", "get", AUDIO_DEV)); size_t vol_bracket = amix_out.find('['); if(vol_bracket != string::npos) { bool is_muted = amix_out.find("[on]") == string::npos; new_stat += is_muted ? "🔇" : "🔉"; size_t first_digit = vol_bracket + 1; size_t close_bracket = amix_out.find(']', first_digit); new_stat.append(amix_out, first_digit, close_bracket - first_digit); new_stat += ' '; } // Time time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); new_stat += (timeinfo->tm_hour/10) + '0'; new_stat += (timeinfo->tm_hour%10) + '0'; new_stat += ':'; new_stat += (timeinfo->tm_min/10) + '0'; new_stat += (timeinfo->tm_min%10) + '0'; strcpy(status, new_stat.c_str()); } void vene_run() // update status bar every 5 sec { time_point now = system_clock::now(); if(has_child && check_exited(child)) { has_child = false; updatestatus(); next_update = now + 10s; } else if(now > next_update) { // Clean up all zombies while (waitpid(-1, nullptr, WNOHANG) > 0); updatestatus(); next_update = now + 10s; } } void vene_webbookmark() { using std::string; Cmd dmenu( "dmenu", "-f", "-b", "-l", "30"); string bookmark (HOME); bookmark += "/sync/bookmarks/web/"; Cmd list_dirs ("ls"); list_dirs += bookmark.c_str(); // Choose bookmark directory bookmark += $(list_dirs | dmenu); bookmark.pop_back(); // remove trailing newline // Choose bookmark string link =$(dmenu < bookmark.c_str()); size_t link_begin = link.find('-') + 1; if(link_begin != string::npos) { Cmd open_bookmark(BROWSER); link = link.substr(link_begin); open_bookmark += link.c_str(); open_bookmark.detach(); } } void vene_inc_vol(const Arg*) { Cmd inc_vol("amixer", "-q", "set", AUDIO_DEV, "3%+"); child = inc_vol.detach(); has_child = true; } void vene_dec_vol(const Arg*) { Cmd dec_vol("amixer", "-q", "set", AUDIO_DEV, "3%-"); child = dec_vol.detach(); has_child = true; } void vene_toggle_vol(const Arg*) { Cmd toggle_vol("amixer", "-q", "set", AUDIO_DEV, "toggle"); child = toggle_vol.detach(); has_child = true; } }