Area activation button is now configurable, aka right-clickable areas.
This commit is contained in:
parent
eb90ab7675
commit
1ab492730b
|
@ -86,12 +86,14 @@ Set the text foreground color. The parameter I<color> can be I<-> or a color in
|
|||
|
||||
Set the text underline color. The parameter I<color> can be I<-> or a color in one of the formats mentioned before. The special value I<-> resets the color to the default one.
|
||||
|
||||
=item B<A>:I<command>:
|
||||
=item B<A>I<button>:I<command>:
|
||||
|
||||
Create a clickable area starting from the current position, when the area is clicked I<command> is executed. The area is closed when a B<A> token, not followed by : is encountered.
|
||||
|
||||
Eg. I<%{A:reboot:} Click here to reboot %{A}>
|
||||
|
||||
The I<button> field is optional, it defaults to the left button, and it's a number ranging from 1 to 5 which maps to the left, middle, right, scroll down and scroll up movements. Your mileage may vary.
|
||||
|
||||
=item B<S>I<dir>
|
||||
|
||||
Change the monitor bar is rendering to. I<dir> can be either
|
||||
|
|
27
bar.c
27
bar.c
|
@ -34,12 +34,12 @@ typedef struct monitor_t {
|
|||
} monitor_t;
|
||||
|
||||
typedef struct area_t {
|
||||
int begin, end, align;
|
||||
int begin, end, align, button;
|
||||
xcb_window_t window;
|
||||
char *cmd;
|
||||
} area_t;
|
||||
|
||||
#define N 10
|
||||
#define N 20
|
||||
|
||||
typedef struct area_stack_t {
|
||||
int pos;
|
||||
|
@ -225,7 +225,7 @@ area_shift (xcb_window_t win, const int align, int delta)
|
|||
}
|
||||
|
||||
bool
|
||||
area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x, const int align)
|
||||
area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x, const int align, const int button)
|
||||
{
|
||||
char *p = str;
|
||||
area_t *a = &astack.slot[astack.pos];
|
||||
|
@ -280,6 +280,7 @@ area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x
|
|||
a->align = align;
|
||||
a->begin = x;
|
||||
a->window = mon->window;
|
||||
a->button = button;
|
||||
|
||||
*end = trail + 1;
|
||||
|
||||
|
@ -291,8 +292,7 @@ parse (char *text)
|
|||
{
|
||||
font_t *cur_font;
|
||||
monitor_t *cur_mon;
|
||||
int pos_x;
|
||||
int align;
|
||||
int pos_x, align, button;
|
||||
char *p = text, *end;
|
||||
uint32_t tmp;
|
||||
|
||||
|
@ -331,7 +331,11 @@ parse (char *text)
|
|||
case 'r': pos_x = 0; align = ALIGN_R; break;
|
||||
|
||||
case 'A':
|
||||
area_add(p, end, &p, cur_mon, pos_x, align);
|
||||
button = XCB_BUTTON_INDEX_1;
|
||||
/* The range is 1-5 */
|
||||
if (isdigit(*p) && (*p > '0' && *p < '6'))
|
||||
button = *p++ - '0';
|
||||
area_add(p, end, &p, cur_mon, pos_x, align, button);
|
||||
break;
|
||||
|
||||
case 'B': bgc = parse_color(p, &p, dbgc); update_gc(); break;
|
||||
|
@ -987,7 +991,7 @@ main (int argc, char **argv)
|
|||
xcb_generic_event_t *ev;
|
||||
xcb_expose_event_t *expose_ev;
|
||||
xcb_button_press_event_t *press_ev;
|
||||
char input[2048] = {0, };
|
||||
char input[4096] = {0, };
|
||||
bool permanent = false;
|
||||
int geom_v[4] = { -1, -1, 0, 0 };
|
||||
|
||||
|
@ -1068,10 +1072,13 @@ main (int argc, char **argv)
|
|||
break;
|
||||
case XCB_BUTTON_PRESS:
|
||||
press_ev = (xcb_button_press_event_t *)ev;
|
||||
/* Respond to left click */
|
||||
if (press_ev->detail == XCB_BUTTON_INDEX_1) {
|
||||
{
|
||||
area_t *area = area_get(press_ev->event, press_ev->event_x);
|
||||
if (area) { write(STDOUT_FILENO, area->cmd, strlen(area->cmd)); write(STDOUT_FILENO, "\n", 1); }
|
||||
/* Respond to the click */
|
||||
if (area && area->button == press_ev->detail) {
|
||||
write(STDOUT_FILENO, area->cmd, strlen(area->cmd));
|
||||
write(STDOUT_FILENO, "\n", 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user