You are not logged in.
Hello ladies and gentlemen,
So I put this in the Programming section as it's pretty technical, despite being related to a window manager.
The purpose of this post is to get an opinion from people much more intelligent than I am on a solution that I came up with for a problem that I created.
So!
Problem: I use a program called flinks to speed read through some articles sometimes. I use dwm. So instead of running flinks somewhere and copying over the url that I wanted to view every time, I thought why not automate the process using the incredibly powerful facilities of dwm for this purpose. Now it is important to note that I use a graphical browser most of the time when I visit the web, and sometimes a "normal" text browser.
Solution: Define a custom command in config.h, and bind it to some key combination. This command definition should fire up an xterm, run flinks, pass the X11 primary selection as the url to open, do it's thing and die when I quit flinks.
This means that the sequence of events is such:
1. I'm browsing some news site, and see an article that I'd like to scan through quickly.
2. I select the url from the url bar with the mouse.
3. I press the defined key combination and dwm launces a floating xterm running flinks on the url that is in the primary selection.
4. I read the article.
5. I press q and the window dies.
Now, the tricky part. Custom commands are run with the "spawn" function in dwm.c, which, in turn, passes all arguments to the the execvp function from unistd.h. This means that if I want to pass the url from the primary selection, I would have to access it somehow through the X11 mechanism, store it in memory and pass that together with the rest of the arguments to spawn. I have 0 experience with X11, and mucking around in the xclip source, I discovered that doing this is actually really complicated. At least it's complicated for someone who is used to doing these things from shell scripts, where I can just run $(xclip -out) and get the primary selection contents with almost no effort. All this to say that I gave up on writing a custom function in config.h to access the primary selection contents the "proper" way.
What I DID do is the following (just some extra lines from the config.h):
static const Rule rules[] = {
{ "UXTerm", NULL, "flinks", 0, True, -1 },
};
static const char *flinkscmd[] = { "/bin/bash", "-c", "xterm -class UXTerm -u8 -e flinks $(xclip -out)", NULL };
static Key keys[] = {
{ MODKEY|ShiftMask, XK_f, spawn, {.v = flinkscmd} },
};
Now, this works for me, and I'm pretty happy about it.
BUT what I invite comments on is how terrible and wrong the above solution is, and how I should have achieved what I wanted to achieve.
Thanks in advance for your insight.
Offline
Well all I can say is that I would have done it the exact same way. That's how it's done in dwm.
Offline