From 5b8797bccd01f847201748eb785d3b606e4c5937 Mon Sep 17 00:00:00 2001 From: Venelin Date: Thu, 18 Jul 2024 15:02:16 +0300 Subject: [PATCH] web bookmarks --- config.h | 8 ++++--- dwm.c | 2 +- vene.cpp | 67 ++++++++++++++++++++++++++++++++++++++------------------ vene.h | 1 + 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/config.h b/config.h index 151ffbc..9dd2751 100644 --- a/config.h +++ b/config.h @@ -32,7 +32,7 @@ static const Rule rules[] = { * WM_NAME(STRING) = title */ /* class instance title tags mask isfloating monitor */ - { NULL, BROWSER, NULL, 1<<7, 0, -1 }, + { BROWSER, NULL, NULL, 1<<7, 0, -1 }, { NULL, "emacs", NULL, 1<<8, 0, -1 } }; @@ -72,7 +72,7 @@ static const char* screenshot [] = { "scrot", "-s", SCREEN_CAPS_DIR, NULL }; static void webbookmark(const Arg* arg){ const Arg tag = {.ui = 1<<7}; - view(&tag); + /* view(&tag); */ vene_webbookmark(); } @@ -113,7 +113,9 @@ static const Key keys[] = { TAGKEYS( XK_5, 4) TAGKEYS( XK_6, 5) TAGKEYS( XK_7, 6) - TAGKEYS_NO_MOVE( XK_b, 7) + { MODKEY, XK_b, vene_browser, {.ui = 1 << 7} }, + { MODKEY|ControlMask, XK_b, toggleview, {.ui = 1 << 7} }, + { MODKEY|ControlMask|ShiftMask, XK_b, toggletag, {.ui = 1 << 7} }, TAGKEYS_NO_MOVE( XK_e, 8) }; diff --git a/dwm.c b/dwm.c index b222cc9..3a6afc1 100644 --- a/dwm.c +++ b/dwm.c @@ -224,7 +224,7 @@ void updatestatus(void); static void updatetitle(Client *c); static void updatewindowtype(Client *c); static void updatewmhints(Client *c); -static void view(const Arg *arg); +void view(const Arg *arg); static Client *wintoclient(Window w); static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); diff --git a/vene.cpp b/vene.cpp index 2d46ada..9902c67 100644 --- a/vene.cpp +++ b/vene.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include // #include "vene.h" #include "vene_env.h" @@ -11,6 +12,7 @@ using namespace std; using namespace std::chrono; using namespace std::chrono_literals; +namespace fs = std::filesystem; char* HOME; char SCREEN_CAPS_DIR[64]; @@ -20,6 +22,7 @@ namespace time_point next_update; bool has_child; Proc child; + Proc browser = {.pid = 0}; } extern "C" @@ -32,6 +35,7 @@ extern "C" const void *v; } Arg; void updatestatus(); + void view(const Arg* arg); // end void vene_setup() @@ -111,38 +115,59 @@ extern "C" } else if(now > next_update) { - // Clean up all zombies - while (waitpid(-1, nullptr, WNOHANG) > 0); - updatestatus(); next_update = now + 10s; } } - void vene_webbookmark() + void vene_browser(const Arg* arg) { - using std::string; - Cmd dmenu( "dmenu", "-f", "-b", "-l", "30"); + if( browser.pid == 0 || check_exited(browser) ) // not running + { + browser = Cmd(BROWSER).detach(); - string bookmark (HOME); - bookmark += "/sync/bookmarks/web/"; + // Clean up all zombies + while (waitpid(-1, nullptr, WNOHANG) > 0); + } + else // running, view it + { + view(arg); + } + } + + void vene_webbookmark() // todo: cppipe exceptions + { + Cmd dmenu( "dmenu", "-b", "-f", "-i", "-l", "30"); + + string bm_root (HOME); + bm_root += "/sync/bookmarks/web/"; Cmd list_dirs ("ls"); - list_dirs += bookmark.c_str(); + list_dirs += bm_root.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) + while(true) { - Cmd open_bookmark(BROWSER); - link = link.substr(link_begin); - open_bookmark += link.c_str(); - open_bookmark.detach(); + // Choose bookmark directory + string dir = $(list_dirs | dmenu); + if( dir.empty() ) + return; + + string bm_dir = bm_root; + bm_dir += dir; + bm_dir.pop_back(); // remove trailing newline + + // Choose bookmark + string link = $(dmenu < bm_dir.c_str()); + + size_t link_begin = link.find('-'); + if(link_begin != string::npos) + { + Cmd open_bookmark(BROWSER); + link = link.substr(link_begin+1); + open_bookmark += link.c_str(); + open_bookmark.detach(); + break; + } } } diff --git a/vene.h b/vene.h index 605303f..46daaf7 100644 --- a/vene.h +++ b/vene.h @@ -15,6 +15,7 @@ void vene_setup(); void vene_updatestatus(char status[]); void vene_run(); +void vene_browser(const Arg*); void vene_webbookmark(); void vene_inc_vol(const Arg*); void vene_dec_vol(const Arg*);