!CONFIG NEWS! Add multi mouse section in [tags] and new section [client] with multi mouse section

This commit is contained in:
Martin Duquesnoy 2012-01-20 19:32:50 +01:00
parent 4ee3ae7638
commit f5f574b6bd
10 changed files with 113 additions and 38 deletions

View File

@ -454,7 +454,7 @@ _client_tab(struct client *c, struct client *cm)
{ {
/* Do not tab already tabed client */ /* Do not tab already tabed client */
if(c->flags & (CLIENT_TABBED | CLIENT_TABMASTER) if(c->flags & (CLIENT_TABBED | CLIENT_TABMASTER)
|| c->tag != cm->tag) || c->tag != cm->tag || c == cm)
return; return;
layout_split_arrange_closed(c); layout_split_arrange_closed(c);
@ -704,6 +704,7 @@ uicb_client_focus_with_wid(Uicb cmd)
static void static void
client_frame_new(struct client *c) client_frame_new(struct client *c)
{ {
struct barwin *frameb;
XSetWindowAttributes at = XSetWindowAttributes at =
{ {
.background_pixel = c->ncol.bg, .background_pixel = c->ncol.bg,
@ -712,32 +713,27 @@ client_frame_new(struct client *c)
.event_mask = BARWIN_MASK | BARWIN_ENTERMASK .event_mask = BARWIN_MASK | BARWIN_ENTERMASK
}; };
c->frame = XCreateWindow(W->dpy, W->root, /* Use a fake barwin only to store mousebinds of frame win */
c->geo.x, c->geo.y, frameb = barwin_new(W->root, 0, 0, 1, 1, 0, 0, false);
c->geo.w, c->geo.h,
0, CopyFromParent, frameb->win =
InputOutput, c->frame = XCreateWindow(W->dpy, W->root,
CopyFromParent, c->geo.x, c->geo.y,
(CWOverrideRedirect | CWBackPixmap c->geo.w, c->geo.h,
| CWBackPixel | CWEventMask), &at); 0, CopyFromParent,
InputOutput,
CopyFromParent,
(CWOverrideRedirect | CWBackPixmap
| CWBackPixel | CWEventMask), &at);
frameb->mousebinds = W->tmp_head.client;
if(c->tbarw > c->border) if(c->tbarw > c->border)
{ {
struct geo g;
Uicb cmd = (Uicb)&c->win;
c->titlebar = barwin_new(c->frame, 0, 0, 1, c->tbarw, c->titlebar = barwin_new(c->frame, 0, 0, 1, c->tbarw,
c->ncol.fg, c->ncol.bg, true); c->ncol.fg, c->ncol.bg, true);
/* TODO: Refer to titlebar config */ c->titlebar->mousebinds = W->tmp_head.client;
barwin_mousebind_new(c->titlebar, Button1, false, g,
uicb_client_focus_with_wid, cmd);
barwin_mousebind_new(c->titlebar, Button1, false, g,
uicb_mouse_move, cmd);
barwin_mousebind_new(c->titlebar, Button2, false, g,
uicb_mouse_tab, cmd);
barwin_mousebind_new(c->titlebar, Button3, false, g,
uicb_mouse_resize, cmd);
} }
XReparentWindow(W->dpy, c->win, c->frame, c->border, c->tbarw); XReparentWindow(W->dpy, c->win, c->frame, c->border, c->tbarw);

View File

@ -11,6 +11,27 @@
#include "infobar.h" #include "infobar.h"
#include "util.h" #include "util.h"
static void
config_mouse_section(struct mbhead *mousebinds, struct conf_sec **sec)
{
int i = 0;
struct mousebind *m;
SLIST_INIT(mousebinds);
for(; sec[i]; ++i)
{
m = xcalloc(1, sizeof(struct mousebind));
m->button = fetch_opt_first(sec[i], "1", "button").num;
m->func = uicb_name_func(fetch_opt_first(sec[i], "", "func").str);
m->cmd = fetch_opt_first(sec[i], "", "cmd").str;
m->use_area = false;
SLIST_INSERT_HEAD(mousebinds, m, next);
}
}
static void static void
config_theme(void) config_theme(void)
{ {
@ -108,7 +129,7 @@ config_tag(void)
{ {
struct screen *s; struct screen *s;
size_t i, n; size_t i, n;
struct conf_sec *sec, **ks; struct conf_sec *sec, **ks, **mb;
char *name; char *name;
int screenid; int screenid;
@ -117,6 +138,13 @@ config_tag(void)
ks = fetch_section(sec, "tag"); ks = fetch_section(sec, "tag");
n = fetch_section_count(ks); n = fetch_section_count(ks);
/* [mouse] */
if((mb = fetch_section(sec, "mouse")))
{
config_mouse_section(&W->tmp_head.tag, mb);
free(mb);
}
/* [tag] */ /* [tag] */
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
@ -131,6 +159,23 @@ config_tag(void)
free(ks); free(ks);
} }
static void
config_client(void)
{
struct conf_sec *sec, **mb;
/* [client] */
sec = fetch_section_first(NULL, "client");
/* [mouse] */
/* for client frame AND titlebar */
if((mb = fetch_section(sec, "mouse")))
{
config_mouse_section(&W->tmp_head.client, mb);
free(mb);
}
}
#define ISTRDUP(t, s) \ #define ISTRDUP(t, s) \
do { \ do { \
if((tmp = s)) \ if((tmp = s)) \
@ -255,6 +300,7 @@ config_init(void)
config_theme(); config_theme();
config_keybind(); config_keybind();
config_tag(); config_tag();
config_client();
config_bars(); config_bars();
config_rule(); config_rule();

View File

@ -35,6 +35,7 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] =
{ "tag_client", uicb_tag_client }, { "tag_client", uicb_tag_client },
{ "tag_move_client_next", uicb_tag_move_client_next }, { "tag_move_client_next", uicb_tag_move_client_next },
{ "tag_move_client_prev", uicb_tag_move_client_prev }, { "tag_move_client_prev", uicb_tag_move_client_prev },
{ "tag_click", uicb_tag_click },
/* Layout */ /* Layout */
{ "layout_vmirror", uicb_layout_vmirror }, { "layout_vmirror", uicb_layout_vmirror },

View File

@ -25,6 +25,8 @@ event_buttonpress(XEvent *e)
SLIST_FOREACH(b, &W->h.barwin, next) SLIST_FOREACH(b, &W->h.barwin, next)
if(b->win == ev->window) if(b->win == ev->window)
{ {
W->last_clicked_barwin = b;
SLIST_FOREACH(m, &b->mousebinds, next) SLIST_FOREACH(m, &b->mousebinds, next)
if(m->button == ev->button) if(m->button == ev->button)
if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area))) if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area)))

View File

@ -36,7 +36,6 @@ infobar_elem_tag_init(struct element *e)
{ {
struct tag *t; struct tag *t;
struct barwin *b, *prev = NULL; struct barwin *b, *prev = NULL;
struct geo g = { 0, 0, 0, 0 };
int s, j; int s, j;
/* Get final size before to use in placement */ /* Get final size before to use in placement */
@ -66,10 +65,7 @@ infobar_elem_tag_init(struct element *e)
b->ptr = (void*)t; b->ptr = (void*)t;
barwin_map(b); barwin_map(b);
/* TODO: refer to tag element configuration */ b->mousebinds = W->tmp_head.tag;
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);
SLIST_INSERT_TAIL(&e->bars, b, enext, prev); SLIST_INSERT_TAIL(&e->bars, b, enext, prev);

View File

@ -90,7 +90,7 @@ mouse_drag_tag(struct client *c, Window w)
#define _REV_SBORDER(c) draw_reversed_rect(W->root, c, false); #define _REV_SBORDER(c) draw_reversed_rect(W->root, c, false);
void void
mouse_move(struct client *c, bool type) mouse_move(struct client *c, void (*func)(struct client*, struct client*))
{ {
struct client *c2 = NULL, *last = c; struct client *c2 = NULL, *last = c;
struct tag *t = NULL; struct tag *t = NULL;
@ -134,15 +134,10 @@ mouse_move(struct client *c, bool type)
if(c2) if(c2)
{ {
if(c2 != c) if(last == c2)
{
_REV_SBORDER(c2); _REV_SBORDER(c2);
if(type) func(c, c2);
client_swap2(c, c2);
else
_client_tab(c, c2);
}
} }
else if(t && t != (struct tag*)c) else if(t && t != (struct tag*)c)
tag_client(t, c); tag_client(t, c);
@ -163,7 +158,7 @@ uicb_mouse_move(Uicb cmd)
(void)cmd; (void)cmd;
if(W->client && mouse_check_client(W->client)) if(W->client && mouse_check_client(W->client))
mouse_move(W->client, true); mouse_move(W->client, client_swap2);
} }
void void
@ -172,5 +167,5 @@ uicb_mouse_tab(Uicb cmd)
(void)cmd; (void)cmd;
if(W->client && mouse_check_client(W->client)) if(W->client && mouse_check_client(W->client))
mouse_move(W->client, false); mouse_move(W->client, _client_tab);
} }

View File

@ -200,6 +200,17 @@ uicb_tag_move_client_prev(Uicb cmd)
tag_client(TAILQ_LAST(&W->screen->tags, tsub), W->client); tag_client(TAILQ_LAST(&W->screen->tags, tsub), W->client);
} }
void
uicb_tag_click(Uicb cmd)
{
(void)cmd;
struct tag *t;
if((t = (struct tag*)W->last_clicked_barwin->ptr)
&& t->screen == W->screen)
tag_screen(W->screen, t);
}
static void static void
tag_remove(struct tag *t) tag_remove(struct tag *t)
{ {

View File

@ -32,6 +32,7 @@ void uicb_tag_prev(Uicb cmd);
void uicb_tag_client(Uicb cmd); void uicb_tag_client(Uicb cmd);
void uicb_tag_move_client_next(Uicb cmd); void uicb_tag_move_client_next(Uicb cmd);
void uicb_tag_move_client_prev(Uicb cmd); void uicb_tag_move_client_prev(Uicb cmd);
void uicb_tag_click(Uicb cmd);
#endif /* TAG_H */ #endif /* TAG_H */

View File

@ -89,7 +89,7 @@ struct barwin
Drawable dr; Drawable dr;
Color fg, bg; Color fg, bg;
void *ptr; /* Special cases */ void *ptr; /* Special cases */
SLIST_HEAD(, mousebind) mousebinds; SLIST_HEAD(mbhead, mousebind) mousebinds;
SLIST_ENTRY(barwin) next; /* global barwin */ SLIST_ENTRY(barwin) next; /* global barwin */
SLIST_ENTRY(barwin) enext; /* element barwin */ SLIST_ENTRY(barwin) enext; /* element barwin */
}; };
@ -279,6 +279,7 @@ struct wmfs
Atom *net_atom; Atom *net_atom;
char **argv; char **argv;
char confpath[MAX_PATH_LEN]; char confpath[MAX_PATH_LEN];
struct barwin *last_clicked_barwin;
/* FIFO stuffs */ /* FIFO stuffs */
struct struct
@ -298,6 +299,18 @@ struct wmfs
SLIST_HEAD(, rule) rule; SLIST_HEAD(, rule) rule;
} h; } h;
/*
* Temporary head of mousebind list from config
* Will be copied in barwin of clickable drawable
* later in code
*/
struct
{
struct mbhead tag;
struct mbhead client;
struct mbhead root;
} tmp_head;
/* /*
* Selected screen, client * Selected screen, client
*/ */

14
wmfsrc
View File

@ -79,8 +79,22 @@
[tag] screen = 0 name = "6" [/tag] [tag] screen = 0 name = "6" [/tag]
[tag] screen = 0 name = "7" [/tag] [tag] screen = 0 name = "7" [/tag]
# Mousebinds associated to Tags element button
[mouse] button = "1" func = "tag_click" [/mouse]
[mouse] button = "4" func = "tag_next" [/mouse]
[mouse] button = "5" func = "tag_prev" [/mouse]
[/tags] [/tags]
[client]
[mouse] button = "1" func = "mouse_swap" [/mouse]
[mouse] button = "2" func = "mouse_tab" [/mouse]
[mouse] button = "3" func = "mouse_resize" [/mouse]
[/client]
[rules] [rules]
[rule] [rule]