-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: statuscmd patch for clickable status bar.
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,6 +193,9 @@ static void clientmessage(XEvent *e); | |
static void configure(Client *c); | ||
static void configurenotify(XEvent *e); | ||
static void configurerequest(XEvent *e); | ||
#if STATUSCMD | ||
static void copyvalidchars(char *text, char *rawtext); | ||
#endif | ||
static Monitor *createmon(void); | ||
static void destroynotify(XEvent *e); | ||
static void detach(Client *c); | ||
|
@@ -303,6 +306,11 @@ static void centeredfloatingmaster(Monitor *m); | |
static Systray *systray = NULL; | ||
static const char broken[] = "broken"; | ||
static char stext[256]; | ||
#if STATUSCMD | ||
static char rawstext[256]; | ||
static int statuscmdn; | ||
static char lastbutton[] = "-"; | ||
#endif | ||
static int screen; | ||
static int sw, sh; /* X display screen geometry width, height */ | ||
static int bh, blw = 0; /* bar geometry */ | ||
|
@@ -559,6 +567,9 @@ buttonpress(XEvent *e) | |
Client *c; | ||
Monitor *m; | ||
XButtonPressedEvent *ev = &e->xbutton; | ||
#if STATUSCMD | ||
*lastbutton = '0' + ev->button; | ||
#endif | ||
|
||
click = ClkRootWin; | ||
/* focus monitor if necessary */ | ||
|
@@ -582,9 +593,32 @@ buttonpress(XEvent *e) | |
arg.ui = 1 << i; | ||
} else if (ev->x < x + blw) | ||
click = ClkLtSymbol; | ||
#if !STATUSCMD | ||
else if (ev->x > selmon->ww - TEXTW(stext) - getsystraywidth()) | ||
click = ClkStatusText; | ||
else | ||
#else | ||
else if (ev->x > selmon->ww - TEXTW(stext) - getsystraywidth() + lrpad) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
chhajedji
Author
Owner
|
||
click = ClkStatusText; | ||
|
||
char *text = rawstext; | ||
int i = -1; | ||
char ch; | ||
statuscmdn = 0; | ||
while (text[++i]) { | ||
if ((unsigned char)text[i] < ' ') { | ||
ch = text[i]; | ||
text[i] = '\0'; | ||
x += TEXTW(text) - lrpad; | ||
text[i] = ch; | ||
text += i+1; | ||
i = -1; | ||
if (x >= ev->x) break; | ||
if (ch <= LENGTH(statuscmds)) statuscmdn = ch - 1; | ||
} | ||
} | ||
} else | ||
#endif | ||
click = ClkWinTitle; | ||
} else if ((c = wintoclient(ev->window))) { | ||
focus(c); | ||
|
@@ -823,6 +857,21 @@ configurerequest(XEvent *e) | |
XSync(dpy, False); | ||
} | ||
|
||
#if STATUSCMD | ||
void | ||
copyvalidchars(char *text, char *rawtext) | ||
{ | ||
int i = -1, j = 0; | ||
|
||
while(rawtext[++i]) { | ||
if ((unsigned char)rawtext[i] >= ' ') { | ||
text[j++] = rawtext[i]; | ||
} | ||
} | ||
text[j] = '\0'; | ||
} | ||
#endif | ||
|
||
Monitor * | ||
createmon(void) | ||
{ | ||
|
@@ -2061,6 +2110,12 @@ spawn(const Arg *arg) | |
{ | ||
if (arg->v == dmenucmd) | ||
dmenumon[0] = '0' + selmon->num; | ||
#if STATUSCMD | ||
else if (arg->v == statuscmd) { | ||
statuscmd[2] = statuscmds[statuscmdn]; | ||
setenv("BUTTON", lastbutton, 1); | ||
} | ||
#endif | ||
if (fork() == 0) { | ||
if (dpy) | ||
close(ConnectionNumber(dpy)); | ||
|
@@ -2516,8 +2571,15 @@ updatesizehints(Client *c) | |
void | ||
updatestatus(void) | ||
{ | ||
#if STATUSCMD | ||
if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) | ||
strcpy(stext, "dwm-"VERSION); | ||
else | ||
copyvalidchars(stext, rawstext); | ||
#else | ||
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) | ||
strcpy(stext, "dwm-"VERSION); | ||
#endif | ||
drawbar(selmon); | ||
updatesystray(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
#define ATTACH_ASIDE (1) | ||
#define STATUSCOLOR (0) | ||
#define FULL_SCREEN (0) | ||
#define STATUSCMD (1) |
If you look closely at the patch for this particular line then you can spot that it uses a little trick here.
Up until now the variable
x
has been used to keep track of where we are on the bar with regards to our calculations, but the statuscmd patch here explicitly sets that to the start of the status text.In your version you just check if
ev->x
is greater than the start of the status text, which means thatx
, which is used to determine how far on the status you have clicked, remains pointing to the end of the layout symbol or something like that.I would recommend against adding the setting of
x
as part of the if statement though as makes it harder to read (and can cause conflicts with other patches such as awesomebar).Within the if statement I'd instead just add this line;