Compare commits
2 Commits
79f88f791c
...
kske-dwm
Author | SHA1 | Date | |
---|---|---|---|
86026a91fe
|
|||
b254f8ee58
|
@ -62,6 +62,8 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
|
||||
#include "selfrestart.c"
|
||||
|
||||
static Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
||||
@ -73,6 +75,7 @@ static Key keys[] = {
|
||||
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_r, reorganizetags, {0} },
|
||||
{ MODKEY, XK_Return, zoom, {0} },
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
@ -99,6 +102,7 @@ static Key keys[] = {
|
||||
TAGKEYS( XK_7, 6)
|
||||
TAGKEYS( XK_8, 7)
|
||||
TAGKEYS( XK_9, 8)
|
||||
{ MODKEY|ShiftMask, XK_r, self_restart, {0} },
|
||||
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
||||
};
|
||||
|
||||
|
28
dwm.c
28
dwm.c
@ -200,6 +200,7 @@ static void pop(Client *);
|
||||
static void propertynotify(XEvent *e);
|
||||
static void quit(const Arg *arg);
|
||||
static Monitor *recttomon(int x, int y, int w, int h);
|
||||
static void reorganizetags(const Arg *arg);
|
||||
static void resize(Client *c, int x, int y, int w, int h, int interact);
|
||||
static void resizeclient(Client *c, int x, int y, int w, int h);
|
||||
static void resizemouse(const Arg *arg);
|
||||
@ -1348,6 +1349,33 @@ recttomon(int x, int y, int w, int h)
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
reorganizetags(const Arg *arg) {
|
||||
Client *c;
|
||||
unsigned int occ, unocc, i;
|
||||
unsigned int tagdest[LENGTH(tags)];
|
||||
|
||||
occ = 0;
|
||||
for (c = selmon->clients; c; c = c->next)
|
||||
occ |= (1 << (ffs(c->tags)-1));
|
||||
unocc = 0;
|
||||
for (i = 0; i < LENGTH(tags); ++i) {
|
||||
while (unocc < i && (occ & (1 << unocc)))
|
||||
unocc++;
|
||||
if (occ & (1 << i)) {
|
||||
tagdest[i] = unocc;
|
||||
occ &= ~(1 << i);
|
||||
occ |= 1 << unocc;
|
||||
}
|
||||
}
|
||||
|
||||
for (c = selmon->clients; c; c = c->next)
|
||||
c->tags = 1 << tagdest[ffs(c->tags)-1];
|
||||
if (selmon->sel)
|
||||
selmon->tagset[selmon->seltags] = selmon->sel->tags;
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
resize(Client *c, int x, int y, int w, int h, int interact)
|
||||
{
|
||||
|
65
selfrestart.c
Normal file
65
selfrestart.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* Magically finds the current's executable path
|
||||
*
|
||||
* I'm doing the do{}while(); trick because Linux (what I'm running) is not
|
||||
* POSIX compilant and so lstat() cannot be trusted on /proc entries
|
||||
*
|
||||
* @return char* the path of the current executable
|
||||
*/
|
||||
char *get_dwm_path(){
|
||||
struct stat s;
|
||||
int r, length, rate = 42;
|
||||
char *path = NULL;
|
||||
|
||||
if(lstat("/proc/self/exe", &s) == -1){
|
||||
perror("lstat:");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
length = s.st_size + 1 - rate;
|
||||
|
||||
do{
|
||||
length+=rate;
|
||||
|
||||
free(path);
|
||||
path = malloc(sizeof(char) * length);
|
||||
|
||||
if(path == NULL){
|
||||
perror("malloc:");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r = readlink("/proc/self/exe", path, length);
|
||||
|
||||
if(r == -1){
|
||||
perror("readlink:");
|
||||
return NULL;
|
||||
}
|
||||
}while(r >= length);
|
||||
|
||||
path[r] = '\0';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* self-restart
|
||||
*
|
||||
* Initially inspired by: Yu-Jie Lin
|
||||
* https://sites.google.com/site/yjlnotes/notes/dwm
|
||||
*/
|
||||
void self_restart(const Arg *arg) {
|
||||
char *const argv[] = {get_dwm_path(), NULL};
|
||||
|
||||
if(argv[0] == NULL){
|
||||
return;
|
||||
}
|
||||
|
||||
execv(argv[0], argv);
|
||||
}
|
Reference in New Issue
Block a user