Set keybind to tag element (and mouse events)
This commit is contained in:
parent
4908e4b183
commit
80d175465d
@ -66,7 +66,7 @@ barwin_remove(Barwin *b)
|
|||||||
XFreePixmap(W->dpy, b->dr);
|
XFreePixmap(W->dpy, b->dr);
|
||||||
|
|
||||||
/* Free mousebinds */
|
/* Free mousebinds */
|
||||||
FREE_LIST(b->mousebinds, Mousebind);
|
FREE_LIST(Mousebind, b->mousebinds);
|
||||||
|
|
||||||
free(b);
|
free(b);
|
||||||
}
|
}
|
||||||
@ -101,9 +101,10 @@ barwin_mousebind_new(Barwin *b, unsigned int button, bool u, Geo a, void (*func)
|
|||||||
m->use_area = u;
|
m->use_area = u;
|
||||||
m->area = a;
|
m->area = a;
|
||||||
m->func = func;
|
m->func = func;
|
||||||
m->cmd = cmd;
|
|
||||||
|
|
||||||
SLIST_INSERT_HEAD(&b->mousebinds, m, next):
|
m->cmd = (cmd ? xstrdup(cmd) : NULL);
|
||||||
|
|
||||||
|
SLIST_INSERT_HEAD(&b->mousebinds, m, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Refresh the Barwin Color
|
/** Refresh the Barwin Color
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
Barwin* barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask);
|
Barwin* barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask);
|
||||||
void barwin_remove(Barwin *b);
|
void barwin_remove(Barwin *b);
|
||||||
void barwin_resize(Barwin *b, int w, int h);
|
void barwin_resize(Barwin *b, int w, int h);
|
||||||
void barwin_mousebind_new(Barwin *b, unsigned int button, bool u, Geo a, void (*func)(Uicb), Uicb cmd)
|
void barwin_mousebind_new(Barwin *b, unsigned int button, bool u, Geo a, void (*func)(Uicb), Uicb cmd);
|
||||||
void barwin_refresh_color(Barwin *b);
|
void barwin_refresh_color(Barwin *b);
|
||||||
|
|
||||||
#endif /* BARWIN_H */
|
#endif /* BARWIN_H */
|
||||||
|
|||||||
@ -23,6 +23,7 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] =
|
|||||||
|
|
||||||
/* Tag */
|
/* Tag */
|
||||||
{ "tag_set", uicb_tag_set },
|
{ "tag_set", uicb_tag_set },
|
||||||
|
{ "tag", uicb_tag_set_with_name },
|
||||||
{ "tag_next", uicb_tag_next },
|
{ "tag_next", uicb_tag_next },
|
||||||
{ "tag_prev", uicb_tag_prev },
|
{ "tag_prev", uicb_tag_prev },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
|
|||||||
@ -15,8 +15,21 @@
|
|||||||
static void
|
static void
|
||||||
event_buttonpress(XEvent *e)
|
event_buttonpress(XEvent *e)
|
||||||
{
|
{
|
||||||
/*XButtonEvent *ev = &e->xbutton;*/
|
XButtonEvent *ev = &e->xbutton;
|
||||||
|
Mousebind *m;
|
||||||
|
Barwin *b;
|
||||||
|
|
||||||
|
SLIST_FOREACH(b, &W->h.barwin, next)
|
||||||
|
if(b->win == ev->window)
|
||||||
|
{
|
||||||
|
SLIST_FOREACH(m, &b->mousebinds, next)
|
||||||
|
if(m->button == ev->button)
|
||||||
|
if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area)))
|
||||||
|
if(m->func)
|
||||||
|
m->func(m->cmd);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -8,12 +8,11 @@
|
|||||||
#include "infobar.h"
|
#include "infobar.h"
|
||||||
#include "barwin.h"
|
#include "barwin.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "tag.h"
|
||||||
|
|
||||||
#define ELEM_DEFAULT_ORDER "tlsS"
|
#define ELEM_DEFAULT_ORDER "tlsS"
|
||||||
#define INFOBAR_DEF_W (12)
|
#define INFOBAR_DEF_W (12)
|
||||||
|
|
||||||
#define ELEMX(e, head) TAILQ_PREV(e, head, next)->geo.
|
|
||||||
|
|
||||||
static void infobar_elem_tag_init(Element *e);
|
static void infobar_elem_tag_init(Element *e);
|
||||||
static void infobar_elem_tag_update(Element *e);
|
static void infobar_elem_tag_update(Element *e);
|
||||||
|
|
||||||
@ -49,7 +48,8 @@ infobar_elem_tag_init(Element *e)
|
|||||||
{
|
{
|
||||||
Tag *t;
|
Tag *t;
|
||||||
Barwin *b, *prev;
|
Barwin *b, *prev;
|
||||||
int tmp, j;
|
Geo g = { 0, 0, 0, 0 };
|
||||||
|
int s, j;
|
||||||
|
|
||||||
infobar_elem_placement(e);
|
infobar_elem_placement(e);
|
||||||
|
|
||||||
@ -57,20 +57,26 @@ infobar_elem_tag_init(Element *e)
|
|||||||
|
|
||||||
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
|
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
|
||||||
{
|
{
|
||||||
tmp = draw_textw(t->name) + PAD;
|
s = draw_textw(t->name) + PAD;
|
||||||
|
|
||||||
b = barwin_new(e->infobar->bar->win, j, 0, tmp, e->geo.h, 0x009900, 0x777777, false);
|
/* Init barwin */
|
||||||
|
b = barwin_new(e->infobar->bar->win, s, 0, tmp, e->geo.h, 0x009900, 0x777777, false);
|
||||||
b->ptr = (void*)t;
|
b->ptr = (void*)t;
|
||||||
barwin_map(b);
|
barwin_map(b);
|
||||||
|
|
||||||
|
/* TODO: refer to tag element configuration */
|
||||||
|
barwin_mousebind_new(b, Button1, false, g, uicb_tag_set_with_name, (Uicb)t->name);
|
||||||
|
barwin_mousebind_new(b, Button4, false, g, uicb_tag_next, NULL);
|
||||||
|
barwin_mousebind_new(b, Button5, false, g, uicb_tag_prev, NULL);
|
||||||
|
|
||||||
|
/* insert_tail with SLIST */
|
||||||
if(SLIST_EMPTY(&e->bars))
|
if(SLIST_EMPTY(&e->bars))
|
||||||
SLIST_INSERT_HEAD(&e->bars, b, next);
|
SLIST_INSERT_HEAD(&e->bars, b, enext);
|
||||||
else
|
else
|
||||||
SLIST_INSERT_AFTER(prev, b, next);
|
SLIST_INSERT_AFTER(prev, b, enext);
|
||||||
|
|
||||||
prev = b;
|
prev = b;
|
||||||
b = NULL;
|
j += s;
|
||||||
j += tmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,11 +86,12 @@ infobar_elem_tag_update(Element *e)
|
|||||||
Tag *t, *sel = e->infobar->screen->seltag;
|
Tag *t, *sel = e->infobar->screen->seltag;
|
||||||
Barwin *b;
|
Barwin *b;
|
||||||
|
|
||||||
SLIST_FOREACH(b, &e->bars, next)
|
SLIST_FOREACH(b, &e->bars, enext)
|
||||||
{
|
{
|
||||||
t = (Tag*)b->ptr;
|
t = (Tag*)b->ptr;
|
||||||
|
|
||||||
/* Selected */
|
/* Selected */
|
||||||
|
/* TODO: color from conf */
|
||||||
if(t == sel)
|
if(t == sel)
|
||||||
{
|
{
|
||||||
b->fg = 0x000000;
|
b->fg = 0x000000;
|
||||||
@ -104,7 +111,7 @@ infobar_elem_tag_update(Element *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
infobar_elem_init(Infobar *i)
|
infobar_elem_init(Infobar *i)
|
||||||
{
|
{
|
||||||
Element *e;
|
Element *e;
|
||||||
@ -155,7 +162,7 @@ infobar_elem_remove(Element *e)
|
|||||||
while(!SLIST_EMPTY(&e->bars))
|
while(!SLIST_EMPTY(&e->bars))
|
||||||
{
|
{
|
||||||
b = SLIST_FIRST(&e->bars);
|
b = SLIST_FIRST(&e->bars);
|
||||||
SLIST_REMOVE_HEAD(&e->bars, next);
|
SLIST_REMOVE_HEAD(&e->bars, enext);
|
||||||
barwin_remove(b);
|
barwin_remove(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,6 +204,7 @@ infobar_init(void)
|
|||||||
void
|
void
|
||||||
infobar_refresh(Infobar *i)
|
infobar_refresh(Infobar *i)
|
||||||
{
|
{
|
||||||
|
i->elemupdate |= FLAGINT(ElemTag);
|
||||||
infobar_elem_update(i);
|
infobar_elem_update(i);
|
||||||
|
|
||||||
barwin_refresh(i->bar);
|
barwin_refresh(i->bar);
|
||||||
|
|||||||
@ -52,6 +52,19 @@ uicb_tag_set(Uicb cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
uicb_tag_set_with_name(Uicb cmd)
|
||||||
|
{
|
||||||
|
Tag *t;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(t, &W->screen->tags, next)
|
||||||
|
if(!strcmp(cmd, t->name))
|
||||||
|
{
|
||||||
|
tag_screen(W->screen, t);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
uicb_tag_next(Uicb cmd)
|
uicb_tag_next(Uicb cmd)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,6 +12,7 @@ Tag *tag_new(Scr33n *s, char *name);
|
|||||||
void tag_screen(Scr33n *s, Tag *t);
|
void tag_screen(Scr33n *s, Tag *t);
|
||||||
void tag_free(Scr33n *s);
|
void tag_free(Scr33n *s);
|
||||||
void uicb_tag_set(Uicb cmd);
|
void uicb_tag_set(Uicb cmd);
|
||||||
|
void uicb_tag_set_with_name(Uicb cmd);
|
||||||
void uicb_tag_next(Uicb cmd);
|
void uicb_tag_next(Uicb cmd);
|
||||||
void uicb_tag_prev(Uicb cmd);
|
void uicb_tag_prev(Uicb cmd);
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,6 @@
|
|||||||
#ifndef UTIL_H
|
#ifndef UTIL_H
|
||||||
#define UTIL_H
|
#define UTIL_H
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "wmfs.h"
|
#include "wmfs.h"
|
||||||
|
|
||||||
/* Todo FREE_LIST(type, head, function_remove) */
|
/* Todo FREE_LIST(type, head, function_remove) */
|
||||||
@ -25,6 +23,7 @@
|
|||||||
#define LEN(x) (sizeof(x) / sizeof(*x))
|
#define LEN(x) (sizeof(x) / sizeof(*x))
|
||||||
#define FLAGINT(i) (1 << i)
|
#define FLAGINT(i) (1 << i)
|
||||||
#define ATOI(s) strtol(s, NULL, 10)
|
#define ATOI(s) strtol(s, NULL, 10)
|
||||||
|
#define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h)
|
||||||
|
|
||||||
void *xmalloc(size_t nmemb, size_t size);
|
void *xmalloc(size_t nmemb, size_t size);
|
||||||
void *xcalloc(size_t nmemb, size_t size);
|
void *xcalloc(size_t nmemb, size_t size);
|
||||||
|
|||||||
@ -120,6 +120,11 @@ wmfs_xinit(void)
|
|||||||
W->numlockmask = (1 << i);
|
W->numlockmask = (1 << i);
|
||||||
XFreeModifiermap(mm);
|
XFreeModifiermap(mm);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Barwin linked list
|
||||||
|
*/
|
||||||
|
SLIST_INIT(&W->h.barwin);
|
||||||
|
|
||||||
W->running = true;
|
W->running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +250,6 @@ wmfs_quit(void)
|
|||||||
XCloseDisplay(W->dpy);
|
XCloseDisplay(W->dpy);
|
||||||
|
|
||||||
free(W->net_atom);
|
free(W->net_atom);
|
||||||
free(W->argv);
|
|
||||||
free(W);
|
free(W);
|
||||||
|
|
||||||
/* Conf stuffs */
|
/* Conf stuffs */
|
||||||
@ -260,14 +264,7 @@ void
|
|||||||
uicb_reload(Uicb cmd)
|
uicb_reload(Uicb cmd)
|
||||||
{
|
{
|
||||||
(void)cmd;
|
(void)cmd;
|
||||||
char *command = xstrdup(W->argv[0]);
|
|
||||||
char **argv = W->argv;
|
|
||||||
|
|
||||||
wmfs_quit();
|
|
||||||
|
|
||||||
for(; command[0] && command[0] == ' '; ++command[0]);
|
|
||||||
|
|
||||||
execvp(command, argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -282,7 +279,6 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
W = (struct Wmfs*)xcalloc(1, sizeof(struct Wmfs));
|
W = (struct Wmfs*)xcalloc(1, sizeof(struct Wmfs));
|
||||||
|
|
||||||
W->argv = argv;
|
|
||||||
|
|
||||||
/* Get X display */
|
/* Get X display */
|
||||||
if(!(W->dpy = XOpenDisplay(NULL)))
|
if(!(W->dpy = XOpenDisplay(NULL)))
|
||||||
|
|||||||
@ -59,7 +59,8 @@ struct Barwin
|
|||||||
Flags flags;
|
Flags flags;
|
||||||
void *ptr; /* Special cases */
|
void *ptr; /* Special cases */
|
||||||
SLIST_HEAD(, Mousebind) mousebinds;
|
SLIST_HEAD(, Mousebind) mousebinds;
|
||||||
SLIST_ENTRY(Barwin) next;
|
SLIST_ENTRY(Barwin) next; /* global barwin */
|
||||||
|
SLIST_ENTRY(Barwin) enext; /* element barwin */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Infobar's element */
|
/* Infobar's element */
|
||||||
@ -136,7 +137,7 @@ struct Mousebind
|
|||||||
bool use_area;
|
bool use_area;
|
||||||
void (*func)(Uicb);
|
void (*func)(Uicb);
|
||||||
Uicb cmd;
|
Uicb cmd;
|
||||||
SLIST_ENTRY(Keybind) next;
|
SLIST_ENTRY(Mousebind) next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Config
|
struct Config
|
||||||
@ -161,7 +162,6 @@ struct Wmfs
|
|||||||
Flags numlockmask;
|
Flags numlockmask;
|
||||||
GC gc;
|
GC gc;
|
||||||
Atom *net_atom;
|
Atom *net_atom;
|
||||||
char **argv;
|
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user