mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
cvsimport
This commit is contained in:
178
conf.c
178
conf.c
@@ -84,39 +84,63 @@ conf_ignore(struct conf *c, char *val)
|
||||
TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry);
|
||||
}
|
||||
|
||||
void
|
||||
conf_gap(struct conf *c, struct screen_ctx *sc)
|
||||
{
|
||||
sc->gap = c->gap;
|
||||
}
|
||||
|
||||
void
|
||||
conf_font(struct conf *c, struct screen_ctx *sc)
|
||||
{
|
||||
font_init(sc, c->font, (const char **)c->menucolor);
|
||||
}
|
||||
|
||||
static char *menu_color_binds[CWM_COLOR_MENU_MAX] = {
|
||||
static char *color_binds[CWM_COLOR_MAX] = {
|
||||
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
|
||||
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
|
||||
"blue", /* CWM_COLOR_BORDER_GROUP */
|
||||
"red", /* CWM_COLOR_BORDER_UNGROUP */
|
||||
"black", /* CWM_COLOR_MENU_FG */
|
||||
"white", /* CWM_COLOR_MENU_BG */
|
||||
"black", /* CWM_COLOR_MENU_FONT */
|
||||
"", /* CWM_COLOR_MENU_FONT_SEL */
|
||||
};
|
||||
|
||||
static char *color_binds[CWM_COLOR_BORDER_MAX] = {
|
||||
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
|
||||
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
|
||||
"blue", /* CWM_COLOR_BORDER_GROUP */
|
||||
"red", /* CWM_COLOR_BORDER_UNGROUP */
|
||||
};
|
||||
|
||||
void
|
||||
conf_color(struct conf *c, struct screen_ctx *sc)
|
||||
conf_screen(struct screen_ctx *sc)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
XftColor xc;
|
||||
|
||||
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
||||
sc->color[i] = xu_getcolor(sc, c->color[i]);
|
||||
sc->gap = Conf.gap;
|
||||
|
||||
sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font);
|
||||
if (sc->xftfont == NULL)
|
||||
errx(1, "XftFontOpenName");
|
||||
|
||||
for (i = 0; i < CWM_COLOR_MAX; i++) {
|
||||
if (*Conf.color[i] == '\0')
|
||||
break;
|
||||
if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||
Conf.color[i], &xc)) {
|
||||
sc->xftcolor[i] = xc;
|
||||
XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc);
|
||||
} else {
|
||||
warnx("XftColorAllocName: '%s'", Conf.color[i]);
|
||||
XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||
color_binds[i], &sc->xftcolor[i]);
|
||||
}
|
||||
}
|
||||
if (i == CWM_COLOR_MAX)
|
||||
return;
|
||||
|
||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
|
||||
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
|
||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
|
||||
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
|
||||
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
||||
warnx("XftColorAllocValue: '%s'", Conf.color[i]);
|
||||
|
||||
sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1,
|
||||
Conf.bwidth,
|
||||
sc->xftcolor[CWM_COLOR_MENU_FG].pixel,
|
||||
sc->xftcolor[CWM_COLOR_MENU_BG].pixel);
|
||||
|
||||
sc->xftdraw = XftDrawCreate(X_Dpy, sc->menuwin,
|
||||
sc->visual, sc->colormap);
|
||||
if (sc->xftdraw == NULL)
|
||||
errx(1, "XftDrawCreate");
|
||||
|
||||
conf_grab_kbd(sc->rootwin);
|
||||
}
|
||||
|
||||
static struct {
|
||||
@@ -195,7 +219,7 @@ m_binds[] = {
|
||||
void
|
||||
conf_init(struct conf *c)
|
||||
{
|
||||
int i;
|
||||
u_int i;
|
||||
|
||||
bzero(c, sizeof(*c));
|
||||
|
||||
@@ -218,9 +242,6 @@ conf_init(struct conf *c)
|
||||
for (i = 0; i < nitems(color_binds); i++)
|
||||
c->color[i] = xstrdup(color_binds[i]);
|
||||
|
||||
for (i = 0; i < nitems(menu_color_binds); i++)
|
||||
c->menucolor[i] = xstrdup(menu_color_binds[i]);
|
||||
|
||||
/* Default term/lock */
|
||||
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
||||
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
||||
@@ -268,7 +289,7 @@ conf_clear(struct conf *c)
|
||||
free(mb);
|
||||
}
|
||||
|
||||
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
||||
for (i = 0; i < CWM_COLOR_MAX; i++)
|
||||
free(c->color[i]);
|
||||
|
||||
free(c->font);
|
||||
@@ -413,37 +434,6 @@ static struct {
|
||||
{.i = CWM_TILE_VERT } },
|
||||
};
|
||||
|
||||
/*
|
||||
* The following two functions are used when grabbing and ungrabbing keys for
|
||||
* bindings
|
||||
*/
|
||||
|
||||
/*
|
||||
* Grab key combination on all screens and add to the global queue
|
||||
*/
|
||||
void
|
||||
conf_grab(struct conf *c, struct keybinding *kb)
|
||||
{
|
||||
extern struct screen_ctx_q Screenq;
|
||||
struct screen_ctx *sc;
|
||||
|
||||
TAILQ_FOREACH(sc, &Screenq, entry)
|
||||
xu_key_grab(sc->rootwin, kb->modmask, kb->keysym);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ungrab key combination from all screens and remove from global queue
|
||||
*/
|
||||
void
|
||||
conf_ungrab(struct conf *c, struct keybinding *kb)
|
||||
{
|
||||
extern struct screen_ctx_q Screenq;
|
||||
struct screen_ctx *sc;
|
||||
|
||||
TAILQ_FOREACH(sc, &Screenq, entry)
|
||||
xu_key_ungrab(sc->rootwin, kb->modmask, kb->keysym);
|
||||
}
|
||||
|
||||
static struct {
|
||||
char chr;
|
||||
int mask;
|
||||
@@ -459,7 +449,7 @@ conf_bindname(struct conf *c, char *name, char *binding)
|
||||
{
|
||||
struct keybinding *current_binding;
|
||||
char *substring, *tmp;
|
||||
int i;
|
||||
u_int i;
|
||||
|
||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
||||
|
||||
@@ -507,7 +497,6 @@ conf_bindname(struct conf *c, char *name, char *binding)
|
||||
current_binding->flags = name_to_kbfunc[i].flags;
|
||||
current_binding->argument = name_to_kbfunc[i].argument;
|
||||
current_binding->argtype |= ARG_INT;
|
||||
conf_grab(c, current_binding);
|
||||
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
||||
return;
|
||||
}
|
||||
@@ -516,7 +505,6 @@ conf_bindname(struct conf *c, char *name, char *binding)
|
||||
current_binding->flags = 0;
|
||||
current_binding->argument.c = xstrdup(binding);
|
||||
current_binding->argtype |= ARG_CHAR;
|
||||
conf_grab(c, current_binding);
|
||||
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
||||
}
|
||||
|
||||
@@ -532,7 +520,6 @@ conf_unbind(struct conf *c, struct keybinding *unbind)
|
||||
if ((key->keycode != 0 && key->keysym == NoSymbol &&
|
||||
key->keycode == unbind->keycode) ||
|
||||
key->keysym == unbind->keysym) {
|
||||
conf_ungrab(c, key);
|
||||
TAILQ_REMOVE(&c->keybindingq, key, entry);
|
||||
if (key->argtype & ARG_CHAR)
|
||||
free(key->argument.c);
|
||||
@@ -558,13 +545,16 @@ static struct {
|
||||
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT },
|
||||
};
|
||||
|
||||
void
|
||||
static unsigned int mouse_btns[] = { Button1, Button2, Button3 };
|
||||
|
||||
int
|
||||
conf_mousebind(struct conf *c, char *name, char *binding)
|
||||
{
|
||||
struct mousebinding *current_binding;
|
||||
char *substring, *tmp;
|
||||
u_int button;
|
||||
const char *errstr;
|
||||
int i;
|
||||
u_int i;
|
||||
|
||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
||||
|
||||
@@ -581,16 +571,27 @@ conf_mousebind(struct conf *c, char *name, char *binding)
|
||||
} else
|
||||
substring = name;
|
||||
|
||||
current_binding->button = strtonum(substring, 1, 3, &errstr);
|
||||
button = strtonum(substring, 1, 3, &errstr);
|
||||
if (errstr)
|
||||
warnx("number of buttons is %s: %s", errstr, substring);
|
||||
warnx("button number is %s: %s", errstr, substring);
|
||||
|
||||
for (i = 0; i < nitems(mouse_btns); i++) {
|
||||
if (button == mouse_btns[i]) {
|
||||
current_binding->button = button;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!current_binding->button || errstr) {
|
||||
free(current_binding);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* We now have the correct binding, remove duplicates. */
|
||||
conf_mouseunbind(c, current_binding);
|
||||
|
||||
if (strcmp("unmap", binding) == 0) {
|
||||
free(current_binding);
|
||||
return;
|
||||
return (1);
|
||||
}
|
||||
|
||||
for (i = 0; i < nitems(name_to_mousefunc); i++) {
|
||||
@@ -600,8 +601,10 @@ conf_mousebind(struct conf *c, char *name, char *binding)
|
||||
current_binding->context = name_to_mousefunc[i].context;
|
||||
current_binding->callback = name_to_mousefunc[i].handler;
|
||||
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
|
||||
return;
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -620,33 +623,26 @@ conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Grab the mouse buttons that we need for bindings for this client
|
||||
*/
|
||||
void
|
||||
conf_grab_mouse(struct client_ctx *cc)
|
||||
conf_grab_mouse(Window win)
|
||||
{
|
||||
struct mousebinding *mb;
|
||||
int button;
|
||||
|
||||
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
||||
if (mb->context != MOUSEBIND_CTX_WIN)
|
||||
continue;
|
||||
|
||||
switch(mb->button) {
|
||||
case 1:
|
||||
button = Button1;
|
||||
break;
|
||||
case 2:
|
||||
button = Button2;
|
||||
break;
|
||||
case 3:
|
||||
button = Button3;
|
||||
break;
|
||||
default:
|
||||
warnx("strange button in mousebinding\n");
|
||||
continue;
|
||||
}
|
||||
xu_btn_grab(cc->win, mb->modmask, button);
|
||||
xu_btn_grab(win, mb->modmask, mb->button);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
conf_grab_kbd(Window win)
|
||||
{
|
||||
struct keybinding *kb;
|
||||
|
||||
XUngrabKey(X_Dpy, AnyKey, AnyModifier, win);
|
||||
|
||||
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
||||
xu_key_grab(win, kb->modmask, kb->keysym);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user