2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
2008-01-11 19:06:44 +03:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-04-27 21:58:48 +04:00
|
|
|
*
|
2011-05-11 17:53:51 +04:00
|
|
|
* $OpenBSD$
|
2007-04-27 21:58:48 +04:00
|
|
|
*/
|
|
|
|
|
2015-01-19 17:54:16 +03:00
|
|
|
#include <sys/types.h>
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2015-01-19 17:54:16 +03:00
|
|
|
#include <limits.h>
|
2012-11-09 07:52:02 +04:00
|
|
|
#include <stdio.h>
|
2009-12-15 07:10:42 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2014-01-03 19:29:06 +04:00
|
|
|
static const char *conf_bind_getmask(const char *, unsigned int *);
|
2015-06-30 21:42:50 +03:00
|
|
|
static void conf_cmd_remove(struct conf *, const char *);
|
|
|
|
static void conf_unbind_kbd(struct conf *, struct binding *);
|
|
|
|
static void conf_unbind_mouse(struct conf *, struct binding *);
|
2009-06-26 16:21:58 +04:00
|
|
|
|
2014-01-29 22:34:22 +04:00
|
|
|
int
|
2014-01-21 01:34:32 +04:00
|
|
|
conf_cmd_add(struct conf *c, const char *name, const char *path)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2015-08-21 18:55:39 +03:00
|
|
|
struct cmd *cmd;
|
2014-01-29 22:34:22 +04:00
|
|
|
|
2014-09-06 20:14:35 +04:00
|
|
|
cmd = xmalloc(sizeof(*cmd));
|
2014-01-29 22:43:27 +04:00
|
|
|
|
2014-09-06 20:14:35 +04:00
|
|
|
cmd->name = xstrdup(name);
|
|
|
|
if (strlcpy(cmd->path, path, sizeof(cmd->path)) >= sizeof(cmd->path)) {
|
|
|
|
free(cmd->name);
|
|
|
|
free(cmd);
|
|
|
|
return(0);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
2014-09-06 20:14:35 +04:00
|
|
|
|
|
|
|
conf_cmd_remove(c, name);
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
|
2015-06-30 21:44:29 +03:00
|
|
|
|
2014-09-06 20:14:35 +04:00
|
|
|
return(1);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2014-01-29 22:43:27 +04:00
|
|
|
static void
|
|
|
|
conf_cmd_remove(struct conf *c, const char *name)
|
|
|
|
{
|
|
|
|
struct cmd *cmd = NULL, *cmdnxt;
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(cmd, &c->cmdq, entry, cmdnxt) {
|
|
|
|
if (strcmp(cmd->name, name) == 0) {
|
|
|
|
TAILQ_REMOVE(&c->cmdq, cmd, entry);
|
2014-02-02 19:46:05 +04:00
|
|
|
free(cmd->name);
|
2014-01-29 22:43:27 +04:00
|
|
|
free(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-17 17:30:38 +04:00
|
|
|
void
|
2015-05-17 07:34:01 +03:00
|
|
|
conf_autogroup(struct conf *c, int num, const char *name, const char *class)
|
2013-04-17 17:30:38 +04:00
|
|
|
{
|
|
|
|
struct autogroupwin *aw;
|
|
|
|
char *p;
|
|
|
|
|
2015-01-24 21:16:59 +03:00
|
|
|
aw = xmalloc(sizeof(*aw));
|
2013-04-17 17:30:38 +04:00
|
|
|
|
2015-05-17 07:34:01 +03:00
|
|
|
if ((p = strchr(class, ',')) == NULL) {
|
|
|
|
if (name == NULL)
|
|
|
|
aw->name = NULL;
|
|
|
|
else
|
|
|
|
aw->name = xstrdup(name);
|
|
|
|
|
|
|
|
aw->class = xstrdup(class);
|
2013-04-17 17:30:38 +04:00
|
|
|
} else {
|
|
|
|
*(p++) = '\0';
|
2015-05-17 07:34:01 +03:00
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
aw->name = xstrdup(class);
|
|
|
|
else
|
|
|
|
aw->name = xstrdup(name);
|
|
|
|
|
2013-04-17 17:30:38 +04:00
|
|
|
aw->class = xstrdup(p);
|
|
|
|
}
|
2014-08-20 19:15:29 +04:00
|
|
|
aw->num = num;
|
2013-04-17 17:30:38 +04:00
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&c->autogroupq, aw, entry);
|
|
|
|
}
|
|
|
|
|
2014-01-31 02:17:22 +04:00
|
|
|
void
|
|
|
|
conf_ignore(struct conf *c, const char *name)
|
2013-04-17 17:30:38 +04:00
|
|
|
{
|
2014-01-31 02:17:22 +04:00
|
|
|
struct winname *wn;
|
2013-04-17 17:30:38 +04:00
|
|
|
|
2015-01-23 23:26:36 +03:00
|
|
|
wn = xmalloc(sizeof(*wn));
|
2014-01-31 02:17:22 +04:00
|
|
|
wn->name = xstrdup(name);
|
|
|
|
TAILQ_INSERT_TAIL(&c->ignoreq, wn, entry);
|
2013-04-17 17:30:38 +04:00
|
|
|
}
|
|
|
|
|
2014-01-21 19:42:44 +04:00
|
|
|
static const char *color_binds[] = {
|
2013-01-04 20:23:51 +04:00
|
|
|
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
|
|
|
|
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
|
2013-12-13 18:40:52 +04:00
|
|
|
"#FC8814", /* CWM_COLOR_BORDER_URGENCY */
|
2013-01-04 20:23:51 +04:00
|
|
|
"blue", /* CWM_COLOR_BORDER_GROUP */
|
|
|
|
"red", /* CWM_COLOR_BORDER_UNGROUP */
|
2013-05-20 03:09:59 +04:00
|
|
|
"black", /* CWM_COLOR_MENU_FG */
|
|
|
|
"white", /* CWM_COLOR_MENU_BG */
|
|
|
|
"black", /* CWM_COLOR_MENU_FONT */
|
|
|
|
"", /* CWM_COLOR_MENU_FONT_SEL */
|
2011-09-03 13:25:39 +04:00
|
|
|
};
|
|
|
|
|
2009-05-18 03:40:57 +04:00
|
|
|
void
|
2013-05-12 01:46:27 +04:00
|
|
|
conf_screen(struct screen_ctx *sc)
|
2009-05-18 03:40:57 +04:00
|
|
|
{
|
2014-01-03 19:29:06 +04:00
|
|
|
unsigned int i;
|
2013-07-10 18:11:42 +04:00
|
|
|
XftColor xc;
|
2014-02-02 20:29:04 +04:00
|
|
|
Colormap colormap = DefaultColormap(X_Dpy, sc->which);
|
|
|
|
Visual *visual = DefaultVisual(X_Dpy, sc->which);
|
2009-05-18 03:40:57 +04:00
|
|
|
|
2013-05-12 01:46:27 +04:00
|
|
|
sc->gap = Conf.gap;
|
2013-11-27 22:34:34 +04:00
|
|
|
sc->snapdist = Conf.snapdist;
|
2013-05-12 01:46:27 +04:00
|
|
|
|
2013-10-07 17:40:26 +04:00
|
|
|
sc->xftfont = XftFontOpenXlfd(X_Dpy, sc->which, Conf.font);
|
|
|
|
if (sc->xftfont == NULL) {
|
|
|
|
sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font);
|
|
|
|
if (sc->xftfont == NULL)
|
2016-08-13 12:59:48 +03:00
|
|
|
errx(1, "XftFontOpenName: %s", Conf.font);
|
2013-10-07 17:40:26 +04:00
|
|
|
}
|
2013-05-12 01:46:27 +04:00
|
|
|
|
2013-06-23 21:57:50 +04:00
|
|
|
for (i = 0; i < nitems(color_binds); i++) {
|
|
|
|
if (i == CWM_COLOR_MENU_FONT_SEL && *Conf.color[i] == '\0') {
|
|
|
|
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);
|
2014-02-02 20:29:04 +04:00
|
|
|
if (!XftColorAllocValue(X_Dpy, visual, colormap,
|
2013-06-23 21:57:50 +04:00
|
|
|
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
2014-01-23 21:13:38 +04:00
|
|
|
warnx("XftColorAllocValue: %s", Conf.color[i]);
|
2013-05-20 03:09:59 +04:00
|
|
|
break;
|
2013-06-23 21:57:50 +04:00
|
|
|
}
|
2014-02-02 20:29:04 +04:00
|
|
|
if (XftColorAllocName(X_Dpy, visual, colormap,
|
2013-05-20 03:09:59 +04:00
|
|
|
Conf.color[i], &xc)) {
|
|
|
|
sc->xftcolor[i] = xc;
|
2014-02-02 20:29:04 +04:00
|
|
|
XftColorFree(X_Dpy, visual, colormap, &xc);
|
2013-05-20 03:09:59 +04:00
|
|
|
} else {
|
2014-01-23 21:13:38 +04:00
|
|
|
warnx("XftColorAllocName: %s", Conf.color[i]);
|
2014-02-02 20:29:04 +04:00
|
|
|
XftColorAllocName(X_Dpy, visual, colormap,
|
2013-05-20 03:09:59 +04:00
|
|
|
color_binds[i], &sc->xftcolor[i]);
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 21:57:50 +04:00
|
|
|
|
2016-09-29 03:21:55 +03:00
|
|
|
sc->menu.win = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1,
|
2013-05-21 00:21:04 +04:00
|
|
|
Conf.bwidth,
|
|
|
|
sc->xftcolor[CWM_COLOR_MENU_FG].pixel,
|
|
|
|
sc->xftcolor[CWM_COLOR_MENU_BG].pixel);
|
|
|
|
|
2016-09-29 03:21:55 +03:00
|
|
|
sc->menu.xftdraw = XftDrawCreate(X_Dpy, sc->menu.win, visual, colormap);
|
|
|
|
if (sc->menu.xftdraw == NULL)
|
2013-05-21 00:21:04 +04:00
|
|
|
errx(1, "XftDrawCreate");
|
2013-05-22 20:54:09 +04:00
|
|
|
|
2013-05-23 20:52:39 +04:00
|
|
|
conf_grab_kbd(sc->rootwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2014-01-21 19:42:44 +04:00
|
|
|
static const struct {
|
|
|
|
const char *key;
|
|
|
|
const char *func;
|
2013-07-08 20:32:51 +04:00
|
|
|
} kbd_binds[] = {
|
2009-08-25 05:42:05 +04:00
|
|
|
{ "CM-Return", "terminal" },
|
|
|
|
{ "CM-Delete", "lock" },
|
|
|
|
{ "M-question", "exec" },
|
|
|
|
{ "CM-w", "exec_wm" },
|
|
|
|
{ "M-period", "ssh" },
|
|
|
|
{ "M-Return", "hide" },
|
|
|
|
{ "M-Down", "lower" },
|
|
|
|
{ "M-Up", "raise" },
|
|
|
|
{ "M-slash", "search" },
|
|
|
|
{ "C-slash", "menusearch" },
|
|
|
|
{ "M-Tab", "cycle" },
|
|
|
|
{ "MS-Tab", "rcycle" },
|
|
|
|
{ "CM-n", "label" },
|
|
|
|
{ "CM-x", "delete" },
|
|
|
|
{ "CM-0", "nogroup" },
|
|
|
|
{ "CM-1", "group1" },
|
|
|
|
{ "CM-2", "group2" },
|
|
|
|
{ "CM-3", "group3" },
|
|
|
|
{ "CM-4", "group4" },
|
|
|
|
{ "CM-5", "group5" },
|
|
|
|
{ "CM-6", "group6" },
|
|
|
|
{ "CM-7", "group7" },
|
|
|
|
{ "CM-8", "group8" },
|
|
|
|
{ "CM-9", "group9" },
|
|
|
|
{ "M-Right", "cyclegroup" },
|
|
|
|
{ "M-Left", "rcyclegroup" },
|
|
|
|
{ "CM-g", "grouptoggle" },
|
2013-12-16 23:02:17 +04:00
|
|
|
{ "CM-f", "fullscreen" },
|
|
|
|
{ "CM-m", "maximize" },
|
2016-09-12 16:47:00 +03:00
|
|
|
{ "CM-s", "stick" },
|
2009-08-25 05:42:05 +04:00
|
|
|
{ "CM-equal", "vmaximize" },
|
|
|
|
{ "CMS-equal", "hmaximize" },
|
2011-05-07 21:15:37 +04:00
|
|
|
{ "CMS-f", "freeze" },
|
2012-10-31 23:30:19 +04:00
|
|
|
{ "CMS-r", "restart" },
|
2009-08-25 05:42:05 +04:00
|
|
|
{ "CMS-q", "quit" },
|
|
|
|
{ "M-h", "moveleft" },
|
|
|
|
{ "M-j", "movedown" },
|
|
|
|
{ "M-k", "moveup" },
|
|
|
|
{ "M-l", "moveright" },
|
2015-08-20 17:45:15 +03:00
|
|
|
{ "MS-h", "bigmoveleft" },
|
|
|
|
{ "MS-j", "bigmovedown" },
|
|
|
|
{ "MS-k", "bigmoveup" },
|
|
|
|
{ "MS-l", "bigmoveright" },
|
2009-08-25 05:42:05 +04:00
|
|
|
{ "CM-h", "resizeleft" },
|
|
|
|
{ "CM-j", "resizedown" },
|
|
|
|
{ "CM-k", "resizeup" },
|
|
|
|
{ "CM-l", "resizeright" },
|
2015-08-20 17:45:15 +03:00
|
|
|
{ "CMS-h", "bigresizeleft" },
|
|
|
|
{ "CMS-j", "bigresizedown" },
|
|
|
|
{ "CMS-k", "bigresizeup" },
|
|
|
|
{ "CMS-l", "bigresizeright" },
|
2009-08-25 05:42:05 +04:00
|
|
|
{ "C-Left", "ptrmoveleft" },
|
|
|
|
{ "C-Down", "ptrmovedown" },
|
|
|
|
{ "C-Up", "ptrmoveup" },
|
|
|
|
{ "C-Right", "ptrmoveright" },
|
|
|
|
{ "CS-Left", "bigptrmoveleft" },
|
|
|
|
{ "CS-Down", "bigptrmovedown" },
|
|
|
|
{ "CS-Up", "bigptrmoveup" },
|
|
|
|
{ "CS-Right", "bigptrmoveright" },
|
|
|
|
},
|
2013-07-08 20:32:51 +04:00
|
|
|
mouse_binds[] = {
|
2009-08-25 05:42:05 +04:00
|
|
|
{ "1", "menu_unhide" },
|
|
|
|
{ "2", "menu_group" },
|
|
|
|
{ "3", "menu_cmd" },
|
|
|
|
{ "M-1", "window_move" },
|
|
|
|
{ "CM-1", "window_grouptoggle" },
|
|
|
|
{ "M-2", "window_resize" },
|
|
|
|
{ "M-3", "window_lower" },
|
|
|
|
{ "CMS-3", "window_hide" },
|
|
|
|
};
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
void
|
2008-03-23 18:09:21 +03:00
|
|
|
conf_init(struct conf *c)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2014-01-03 19:29:06 +04:00
|
|
|
unsigned int i;
|
2009-08-25 05:42:05 +04:00
|
|
|
|
2016-10-03 17:42:34 +03:00
|
|
|
c->stickygroups = 0;
|
|
|
|
c->bwidth = 1;
|
|
|
|
c->mamount = 1;
|
|
|
|
c->snapdist = 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-03-23 18:09:21 +03:00
|
|
|
TAILQ_INIT(&c->ignoreq);
|
|
|
|
TAILQ_INIT(&c->cmdq);
|
2008-04-16 00:24:41 +04:00
|
|
|
TAILQ_INIT(&c->keybindingq);
|
2008-03-23 18:09:21 +03:00
|
|
|
TAILQ_INIT(&c->autogroupq);
|
2008-06-15 01:48:54 +04:00
|
|
|
TAILQ_INIT(&c->mousebindingq);
|
2007-11-20 01:18:16 +03:00
|
|
|
|
2013-07-08 20:32:51 +04:00
|
|
|
for (i = 0; i < nitems(kbd_binds); i++)
|
|
|
|
conf_bind_kbd(c, kbd_binds[i].key, kbd_binds[i].func);
|
2009-08-25 05:42:05 +04:00
|
|
|
|
2013-07-08 20:32:51 +04:00
|
|
|
for (i = 0; i < nitems(mouse_binds); i++)
|
|
|
|
conf_bind_mouse(c, mouse_binds[i].key, mouse_binds[i].func);
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2011-09-03 13:25:39 +04:00
|
|
|
for (i = 0; i < nitems(color_binds); i++)
|
2013-01-04 20:23:04 +04:00
|
|
|
c->color[i] = xstrdup(color_binds[i]);
|
2011-09-03 13:25:39 +04:00
|
|
|
|
2014-01-29 22:34:22 +04:00
|
|
|
conf_cmd_add(c, "lock", "xlock");
|
|
|
|
conf_cmd_add(c, "term", "xterm");
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2012-12-18 03:54:57 +04:00
|
|
|
(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
|
|
|
|
homedir, ".ssh/known_hosts");
|
|
|
|
|
2016-10-03 17:42:34 +03:00
|
|
|
c->font = xstrdup("sans-serif:pixelsize=14:bold");
|
2008-03-23 18:09:21 +03:00
|
|
|
}
|
|
|
|
|
2009-01-23 22:00:59 +03:00
|
|
|
void
|
|
|
|
conf_clear(struct conf *c)
|
|
|
|
{
|
2014-01-30 19:43:53 +04:00
|
|
|
struct autogroupwin *aw;
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *kb, *mb;
|
2014-01-31 02:17:22 +04:00
|
|
|
struct winname *wn;
|
2009-01-23 22:00:59 +03:00
|
|
|
struct cmd *cmd;
|
2009-05-18 03:40:57 +04:00
|
|
|
int i;
|
2009-01-23 22:00:59 +03:00
|
|
|
|
|
|
|
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->cmdq, cmd, entry);
|
2014-02-02 19:46:05 +04:00
|
|
|
free(cmd->name);
|
2012-11-08 00:34:39 +04:00
|
|
|
free(cmd);
|
2009-01-23 22:00:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->keybindingq, kb, entry);
|
2012-11-08 00:34:39 +04:00
|
|
|
free(kb);
|
2009-01-23 22:00:59 +03:00
|
|
|
}
|
|
|
|
|
2014-01-30 19:43:53 +04:00
|
|
|
while ((aw = TAILQ_FIRST(&c->autogroupq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->autogroupq, aw, entry);
|
|
|
|
free(aw->class);
|
|
|
|
free(aw->name);
|
|
|
|
free(aw);
|
2009-01-23 22:00:59 +03:00
|
|
|
}
|
|
|
|
|
2014-01-31 02:17:22 +04:00
|
|
|
while ((wn = TAILQ_FIRST(&c->ignoreq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->ignoreq, wn, entry);
|
2014-04-21 16:52:14 +04:00
|
|
|
free(wn->name);
|
2014-01-31 02:17:22 +04:00
|
|
|
free(wn);
|
2009-01-23 22:00:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
2012-11-08 00:34:39 +04:00
|
|
|
free(mb);
|
2009-01-23 22:00:59 +03:00
|
|
|
}
|
|
|
|
|
2013-07-16 18:04:44 +04:00
|
|
|
for (i = 0; i < CWM_COLOR_NITEMS; i++)
|
2013-01-04 20:23:04 +04:00
|
|
|
free(c->color[i]);
|
2009-05-18 03:40:57 +04:00
|
|
|
|
2012-11-08 00:34:39 +04:00
|
|
|
free(c->font);
|
2009-01-23 22:00:59 +03:00
|
|
|
}
|
|
|
|
|
2008-05-18 23:43:50 +04:00
|
|
|
void
|
|
|
|
conf_client(struct client_ctx *cc)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2014-01-31 02:17:22 +04:00
|
|
|
struct winname *wn;
|
2008-05-18 23:43:50 +04:00
|
|
|
int ignore = 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2014-01-31 02:17:22 +04:00
|
|
|
TAILQ_FOREACH(wn, &Conf.ignoreq, entry) {
|
|
|
|
if (strncasecmp(wn->name, cc->name, strlen(wn->name)) == 0) {
|
2009-05-30 04:30:27 +04:00
|
|
|
ignore = 1;
|
|
|
|
break;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
2009-05-30 04:30:27 +04:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2015-07-01 17:36:42 +03:00
|
|
|
cc->bwidth = (ignore) ? 0 : Conf.bwidth;
|
|
|
|
cc->flags |= (ignore) ? CLIENT_IGNORE : 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2014-01-21 19:42:44 +04:00
|
|
|
static const struct {
|
|
|
|
const char *tag;
|
2009-01-23 21:58:40 +03:00
|
|
|
void (*handler)(struct client_ctx *, union arg *);
|
2015-11-10 23:05:33 +03:00
|
|
|
int context;
|
2009-01-23 21:58:40 +03:00
|
|
|
union arg argument;
|
2014-08-24 19:49:58 +04:00
|
|
|
} name_to_func[] = {
|
2015-11-10 23:05:33 +03:00
|
|
|
{ "lower", kbfunc_client_lower, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "raise", kbfunc_client_raise, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "search", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} },
|
|
|
|
{ "menusearch", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} },
|
|
|
|
{ "groupsearch", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} },
|
|
|
|
{ "hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "cycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_CLIENT_CYCLE} },
|
|
|
|
{ "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_CLIENT_RCYCLE} },
|
|
|
|
{ "label", kbfunc_client_label, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "delete", kbfunc_client_delete, CWM_CONTEXT_CLIENT, {0} },
|
2015-11-13 00:28:03 +03:00
|
|
|
{ "group1", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 1} },
|
|
|
|
{ "group2", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 2} },
|
|
|
|
{ "group3", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 3} },
|
|
|
|
{ "group4", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 4} },
|
|
|
|
{ "group5", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 5} },
|
|
|
|
{ "group6", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 6} },
|
|
|
|
{ "group7", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 7} },
|
|
|
|
{ "group8", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 8} },
|
|
|
|
{ "group9", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 9} },
|
|
|
|
{ "grouponly1", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 1} },
|
|
|
|
{ "grouponly2", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 2} },
|
|
|
|
{ "grouponly3", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 3} },
|
|
|
|
{ "grouponly4", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 4} },
|
|
|
|
{ "grouponly5", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 5} },
|
|
|
|
{ "grouponly6", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 6} },
|
|
|
|
{ "grouponly7", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 7} },
|
|
|
|
{ "grouponly8", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 8} },
|
|
|
|
{ "grouponly9", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 9} },
|
2015-11-10 23:05:33 +03:00
|
|
|
{ "movetogroup1", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 1} },
|
|
|
|
{ "movetogroup2", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 2} },
|
|
|
|
{ "movetogroup3", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 3} },
|
|
|
|
{ "movetogroup4", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 4} },
|
|
|
|
{ "movetogroup5", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 5} },
|
|
|
|
{ "movetogroup6", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 6} },
|
|
|
|
{ "movetogroup7", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 7} },
|
|
|
|
{ "movetogroup8", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 8} },
|
|
|
|
{ "movetogroup9", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = 9} },
|
2015-11-13 00:28:03 +03:00
|
|
|
{ "nogroup", kbfunc_group_alltoggle, CWM_CONTEXT_SCREEN, {0} },
|
|
|
|
{ "cyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SCREEN,
|
2015-11-10 23:05:33 +03:00
|
|
|
{.i = CWM_CLIENT_CYCLE} },
|
2015-11-13 00:28:03 +03:00
|
|
|
{ "rcyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SCREEN,
|
2015-11-10 23:05:33 +03:00
|
|
|
{.i = CWM_CLIENT_RCYCLE} },
|
|
|
|
{ "cycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} },
|
|
|
|
{ "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} },
|
|
|
|
{ "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = CWM_KBD}},
|
2016-09-12 16:47:00 +03:00
|
|
|
{ "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} },
|
2015-11-10 23:05:33 +03:00
|
|
|
{ "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT,
|
|
|
|
{0} },
|
|
|
|
{ "maximize", kbfunc_client_toggle_maximize, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "vmaximize", kbfunc_client_toggle_vmaximize, CWM_CONTEXT_CLIENT,
|
|
|
|
{0} },
|
|
|
|
{ "hmaximize", kbfunc_client_toggle_hmaximize, CWM_CONTEXT_CLIENT,
|
|
|
|
{0} },
|
|
|
|
{ "freeze", kbfunc_client_toggle_freeze, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "restart", kbfunc_cwm_status, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_EXEC_WM} },
|
|
|
|
{ "quit", kbfunc_cwm_status, CWM_CONTEXT_SCREEN, {.i = CWM_QUIT} },
|
|
|
|
{ "exec", kbfunc_menu_exec, CWM_CONTEXT_SCREEN, {.i = CWM_MENU_EXEC} },
|
|
|
|
{ "exec_wm", kbfunc_menu_exec, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_MENU_EXEC_WM} },
|
|
|
|
{ "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SCREEN, {0} },
|
|
|
|
{ "terminal", kbfunc_exec_term, CWM_CONTEXT_SCREEN, {0} },
|
|
|
|
{ "lock", kbfunc_exec_lock, CWM_CONTEXT_SCREEN, {0} },
|
2015-11-12 21:26:41 +03:00
|
|
|
{ "moveup", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_UP)} },
|
|
|
|
{ "movedown", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_DOWN)} },
|
|
|
|
{ "moveright", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_RIGHT)} },
|
|
|
|
{ "moveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_LEFT)} },
|
|
|
|
{ "bigmoveup", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_UP | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigmovedown", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigmoveright", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigmoveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
|
|
|
|
{ "resizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_UP)} },
|
|
|
|
{ "resizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_DOWN)} },
|
|
|
|
{ "resizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_RIGHT)} },
|
|
|
|
{ "resizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_LEFT)} },
|
|
|
|
{ "bigresizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_UP | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigresizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigresizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigresizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
|
|
|
|
{ "ptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_UP)} },
|
|
|
|
{ "ptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_DOWN)} },
|
|
|
|
{ "ptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_LEFT)} },
|
|
|
|
{ "ptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_RIGHT)} },
|
|
|
|
{ "bigptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_UP | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
|
|
|
|
{ "bigptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
|
2015-11-10 23:05:33 +03:00
|
|
|
{ "htile", kbfunc_client_tile, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = CWM_CLIENT_TILE_HORIZ} },
|
|
|
|
{ "vtile", kbfunc_client_tile, CWM_CONTEXT_CLIENT,
|
|
|
|
{.i = CWM_CLIENT_TILE_VERT} },
|
|
|
|
{ "window_lower", kbfunc_client_lower, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "window_raise", kbfunc_client_raise, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} },
|
|
|
|
{ "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} },
|
2015-11-17 18:19:19 +03:00
|
|
|
{ "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT,
|
2015-11-10 23:05:33 +03:00
|
|
|
{.i = CWM_MOUSE} },
|
2016-09-22 17:36:03 +03:00
|
|
|
{ "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_MOUSE} },
|
|
|
|
{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_MOUSE} },
|
|
|
|
{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN,
|
|
|
|
{.i = CWM_MOUSE} },
|
2007-04-27 21:58:48 +04:00
|
|
|
};
|
|
|
|
|
2014-01-21 19:42:44 +04:00
|
|
|
static const struct {
|
|
|
|
const char ch;
|
|
|
|
int mask;
|
2009-08-25 05:44:39 +04:00
|
|
|
} bind_mods[] = {
|
|
|
|
{ 'C', ControlMask },
|
|
|
|
{ 'M', Mod1Mask },
|
|
|
|
{ '4', Mod4Mask },
|
|
|
|
{ 'S', ShiftMask },
|
|
|
|
};
|
|
|
|
|
2013-07-08 20:10:55 +04:00
|
|
|
static const char *
|
2014-01-03 19:29:06 +04:00
|
|
|
conf_bind_getmask(const char *name, unsigned int *mask)
|
2013-07-08 20:10:55 +04:00
|
|
|
{
|
|
|
|
char *dash;
|
|
|
|
const char *ch;
|
2014-01-03 19:29:06 +04:00
|
|
|
unsigned int i;
|
2013-07-08 20:10:55 +04:00
|
|
|
|
|
|
|
*mask = 0;
|
|
|
|
if ((dash = strchr(name, '-')) == NULL)
|
2014-09-07 23:27:30 +04:00
|
|
|
return(name);
|
2013-07-08 20:10:55 +04:00
|
|
|
for (i = 0; i < nitems(bind_mods); i++) {
|
2013-07-08 20:32:51 +04:00
|
|
|
if ((ch = strchr(name, bind_mods[i].ch)) != NULL && ch < dash)
|
2013-07-08 20:10:55 +04:00
|
|
|
*mask |= bind_mods[i].mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip past modifiers. */
|
2014-09-07 23:27:30 +04:00
|
|
|
return(dash + 1);
|
2013-07-08 20:10:55 +04:00
|
|
|
}
|
|
|
|
|
2014-01-20 23:06:04 +04:00
|
|
|
int
|
|
|
|
conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
|
2007-11-14 02:26:04 +03:00
|
|
|
{
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *kb;
|
|
|
|
const char *key;
|
2015-03-27 00:41:43 +03:00
|
|
|
unsigned int i;
|
2014-01-20 23:06:04 +04:00
|
|
|
|
2015-03-27 00:41:43 +03:00
|
|
|
kb = xmalloc(sizeof(*kb));
|
|
|
|
key = conf_bind_getmask(bind, &kb->modmask);
|
2014-01-20 23:06:04 +04:00
|
|
|
|
2014-01-30 01:13:52 +04:00
|
|
|
kb->press.keysym = XStringToKeysym(key);
|
|
|
|
if (kb->press.keysym == NoSymbol) {
|
2014-01-20 23:06:04 +04:00
|
|
|
warnx("unknown symbol: %s", key);
|
|
|
|
free(kb);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(0);
|
2007-11-14 02:26:04 +03:00
|
|
|
}
|
|
|
|
|
2007-11-20 01:18:16 +03:00
|
|
|
/* We now have the correct binding, remove duplicates. */
|
2014-01-20 23:06:04 +04:00
|
|
|
conf_unbind_kbd(c, kb);
|
2007-11-20 01:18:16 +03:00
|
|
|
|
2014-01-20 23:06:04 +04:00
|
|
|
if (strcmp("unmap", cmd) == 0) {
|
|
|
|
free(kb);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(1);
|
2012-11-08 00:37:55 +04:00
|
|
|
}
|
2007-11-20 01:18:16 +03:00
|
|
|
|
2014-08-24 19:49:58 +04:00
|
|
|
for (i = 0; i < nitems(name_to_func); i++) {
|
|
|
|
if (strcmp(name_to_func[i].tag, cmd) != 0)
|
2007-04-27 21:58:48 +04:00
|
|
|
continue;
|
|
|
|
|
2014-08-24 19:49:58 +04:00
|
|
|
kb->callback = name_to_func[i].handler;
|
2015-11-10 23:05:33 +03:00
|
|
|
kb->context = name_to_func[i].context;
|
2014-08-24 19:49:58 +04:00
|
|
|
kb->argument = name_to_func[i].argument;
|
2014-01-20 23:06:04 +04:00
|
|
|
TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(1);
|
2008-05-18 23:47:19 +04:00
|
|
|
}
|
2007-11-14 02:26:04 +03:00
|
|
|
|
2015-11-10 23:05:33 +03:00
|
|
|
kb->callback = kbfunc_exec;
|
|
|
|
kb->context = CWM_CONTEXT_NONE;
|
2014-01-20 23:06:04 +04:00
|
|
|
kb->argument.c = xstrdup(cmd);
|
|
|
|
TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(1);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
2009-06-26 16:21:58 +04:00
|
|
|
static void
|
2014-01-30 01:13:52 +04:00
|
|
|
conf_unbind_kbd(struct conf *c, struct binding *unbind)
|
2007-11-20 01:18:16 +03:00
|
|
|
{
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *key = NULL, *keynxt;
|
2008-05-18 23:47:19 +04:00
|
|
|
|
2012-11-08 01:01:48 +04:00
|
|
|
TAILQ_FOREACH_SAFE(key, &c->keybindingq, entry, keynxt) {
|
2007-11-20 01:18:16 +03:00
|
|
|
if (key->modmask != unbind->modmask)
|
|
|
|
continue;
|
|
|
|
|
2014-01-30 01:13:52 +04:00
|
|
|
if (key->press.keysym == unbind->press.keysym) {
|
2007-11-20 01:18:16 +03:00
|
|
|
TAILQ_REMOVE(&c->keybindingq, key, entry);
|
2015-11-10 23:05:33 +03:00
|
|
|
if (key->context == CWM_CONTEXT_NONE)
|
2013-01-01 18:33:52 +04:00
|
|
|
free(key->argument.c);
|
2012-11-08 00:34:39 +04:00
|
|
|
free(key);
|
2008-05-18 23:47:19 +04:00
|
|
|
}
|
2007-11-20 01:18:16 +03:00
|
|
|
}
|
|
|
|
}
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2013-05-22 20:32:15 +04:00
|
|
|
int
|
2014-01-20 23:06:04 +04:00
|
|
|
conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *mb;
|
|
|
|
const char *button, *errstr;
|
2015-03-27 00:41:43 +03:00
|
|
|
unsigned int i;
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2015-03-27 00:41:43 +03:00
|
|
|
mb = xmalloc(sizeof(*mb));
|
|
|
|
button = conf_bind_getmask(bind, &mb->modmask);
|
2013-05-22 20:32:15 +04:00
|
|
|
|
2014-01-30 01:13:52 +04:00
|
|
|
mb->press.button = strtonum(button, Button1, Button5, &errstr);
|
2014-01-20 23:06:04 +04:00
|
|
|
if (errstr) {
|
|
|
|
warnx("button number is %s: %s", errstr, button);
|
|
|
|
free(mb);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(0);
|
2013-05-22 20:32:15 +04:00
|
|
|
}
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2012-11-08 01:04:55 +04:00
|
|
|
/* We now have the correct binding, remove duplicates. */
|
2014-01-20 23:06:04 +04:00
|
|
|
conf_unbind_mouse(c, mb);
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2014-01-20 23:06:04 +04:00
|
|
|
if (strcmp("unmap", cmd) == 0) {
|
|
|
|
free(mb);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(1);
|
2012-11-08 00:37:55 +04:00
|
|
|
}
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2014-08-24 19:49:58 +04:00
|
|
|
for (i = 0; i < nitems(name_to_func); i++) {
|
|
|
|
if (strcmp(name_to_func[i].tag, cmd) != 0)
|
2008-06-15 01:48:54 +04:00
|
|
|
continue;
|
|
|
|
|
2014-08-24 19:49:58 +04:00
|
|
|
mb->callback = name_to_func[i].handler;
|
2015-11-10 23:05:33 +03:00
|
|
|
mb->context = name_to_func[i].context;
|
2014-08-24 19:49:58 +04:00
|
|
|
mb->argument = name_to_func[i].argument;
|
2014-01-20 23:06:04 +04:00
|
|
|
TAILQ_INSERT_TAIL(&c->mousebindingq, mb, entry);
|
2014-09-07 23:27:30 +04:00
|
|
|
return(1);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
2013-05-22 20:32:15 +04:00
|
|
|
|
2014-09-07 23:27:30 +04:00
|
|
|
return(0);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
|
|
|
|
2009-06-26 16:21:58 +04:00
|
|
|
static void
|
2014-01-30 01:13:52 +04:00
|
|
|
conf_unbind_mouse(struct conf *c, struct binding *unbind)
|
2008-06-15 01:48:54 +04:00
|
|
|
{
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *mb = NULL, *mbnxt;
|
2008-06-15 01:48:54 +04:00
|
|
|
|
2012-11-08 01:01:48 +04:00
|
|
|
TAILQ_FOREACH_SAFE(mb, &c->mousebindingq, entry, mbnxt) {
|
2008-06-15 01:48:54 +04:00
|
|
|
if (mb->modmask != unbind->modmask)
|
|
|
|
continue;
|
|
|
|
|
2014-01-30 01:13:52 +04:00
|
|
|
if (mb->press.button == unbind->press.button) {
|
2008-06-15 01:48:54 +04:00
|
|
|
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
2012-11-08 00:34:39 +04:00
|
|
|
free(mb);
|
2008-06-15 01:48:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-16 18:22:25 +04:00
|
|
|
static int cursor_binds[] = {
|
2013-06-17 21:11:10 +04:00
|
|
|
XC_left_ptr, /* CF_NORMAL */
|
2016-10-03 21:43:49 +03:00
|
|
|
XC_fleur, /* CF_MOVE */
|
2013-06-17 21:11:10 +04:00
|
|
|
XC_bottom_right_corner, /* CF_RESIZE */
|
2016-10-03 21:43:49 +03:00
|
|
|
XC_question_arrow, /* CF_QUESTION */
|
2013-06-17 21:11:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
conf_cursor(struct conf *c)
|
|
|
|
{
|
2014-01-03 19:29:06 +04:00
|
|
|
unsigned int i;
|
2013-06-17 21:11:10 +04:00
|
|
|
|
|
|
|
for (i = 0; i < nitems(cursor_binds); i++)
|
|
|
|
c->cursor[i] = XCreateFontCursor(X_Dpy, cursor_binds[i]);
|
|
|
|
}
|
|
|
|
|
2016-09-30 21:28:06 +03:00
|
|
|
static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
|
|
|
|
|
2008-06-26 02:37:29 +04:00
|
|
|
void
|
2013-05-23 20:52:39 +04:00
|
|
|
conf_grab_mouse(Window win)
|
2008-06-26 02:37:29 +04:00
|
|
|
{
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *mb;
|
2016-09-30 21:28:06 +03:00
|
|
|
unsigned int i;
|
2008-06-26 02:37:29 +04:00
|
|
|
|
2016-09-30 21:28:06 +03:00
|
|
|
XUngrabButton(X_Dpy, AnyButton, AnyModifier, win);
|
2013-10-19 23:39:34 +04:00
|
|
|
|
2008-06-26 02:37:29 +04:00
|
|
|
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
2016-09-30 21:28:06 +03:00
|
|
|
if (mb->context != CWM_CONTEXT_CLIENT)
|
|
|
|
continue;
|
|
|
|
for (i = 0; i < nitems(ign_mods); i++) {
|
|
|
|
XGrabButton(X_Dpy, mb->press.button,
|
|
|
|
(mb->modmask | ign_mods[i]), win, False,
|
|
|
|
BUTTONMASK, GrabModeAsync, GrabModeSync,
|
|
|
|
None, None);
|
|
|
|
}
|
2008-06-26 02:37:29 +04:00
|
|
|
}
|
2016-09-30 21:28:06 +03:00
|
|
|
|
2008-06-26 02:37:29 +04:00
|
|
|
}
|
2013-05-23 20:52:39 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
conf_grab_kbd(Window win)
|
|
|
|
{
|
2014-01-30 01:13:52 +04:00
|
|
|
struct binding *kb;
|
2016-09-30 21:28:06 +03:00
|
|
|
KeyCode kc;
|
|
|
|
unsigned int i;
|
2013-05-23 20:52:39 +04:00
|
|
|
|
2016-09-30 21:28:06 +03:00
|
|
|
XUngrabKey(X_Dpy, AnyKey, AnyModifier, win);
|
2013-05-23 20:52:39 +04:00
|
|
|
|
2016-09-30 21:28:06 +03:00
|
|
|
TAILQ_FOREACH(kb, &Conf.keybindingq, entry) {
|
|
|
|
kc = XKeysymToKeycode(X_Dpy, kb->press.keysym);
|
|
|
|
if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) &&
|
|
|
|
(XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym))
|
|
|
|
kb->modmask |= ShiftMask;
|
|
|
|
|
|
|
|
for (i = 0; i < nitems(ign_mods); i++)
|
|
|
|
XGrabKey(X_Dpy, kc, (kb->modmask | ign_mods[i]), win,
|
|
|
|
True, GrabModeAsync, GrabModeAsync);
|
|
|
|
}
|
2013-05-23 20:52:39 +04:00
|
|
|
}
|
2013-07-15 18:50:44 +04:00
|
|
|
|
|
|
|
static char *cwmhints[] = {
|
|
|
|
"WM_STATE",
|
|
|
|
"WM_DELETE_WINDOW",
|
|
|
|
"WM_TAKE_FOCUS",
|
|
|
|
"WM_PROTOCOLS",
|
|
|
|
"_MOTIF_WM_HINTS",
|
|
|
|
"UTF8_STRING",
|
|
|
|
"WM_CHANGE_STATE",
|
|
|
|
};
|
|
|
|
static char *ewmhints[] = {
|
|
|
|
"_NET_SUPPORTED",
|
|
|
|
"_NET_SUPPORTING_WM_CHECK",
|
|
|
|
"_NET_ACTIVE_WINDOW",
|
|
|
|
"_NET_CLIENT_LIST",
|
2015-08-24 18:42:57 +03:00
|
|
|
"_NET_CLIENT_LIST_STACKING",
|
2013-07-15 18:50:44 +04:00
|
|
|
"_NET_NUMBER_OF_DESKTOPS",
|
|
|
|
"_NET_CURRENT_DESKTOP",
|
|
|
|
"_NET_DESKTOP_VIEWPORT",
|
|
|
|
"_NET_DESKTOP_GEOMETRY",
|
|
|
|
"_NET_VIRTUAL_ROOTS",
|
|
|
|
"_NET_SHOWING_DESKTOP",
|
|
|
|
"_NET_DESKTOP_NAMES",
|
|
|
|
"_NET_WORKAREA",
|
|
|
|
"_NET_WM_NAME",
|
|
|
|
"_NET_WM_DESKTOP",
|
|
|
|
"_NET_CLOSE_WINDOW",
|
|
|
|
"_NET_WM_STATE",
|
2014-08-25 16:49:19 +04:00
|
|
|
"_NET_WM_STATE_STICKY",
|
2013-07-15 18:50:44 +04:00
|
|
|
"_NET_WM_STATE_MAXIMIZED_VERT",
|
|
|
|
"_NET_WM_STATE_MAXIMIZED_HORZ",
|
2014-09-17 20:00:44 +04:00
|
|
|
"_NET_WM_STATE_HIDDEN",
|
2013-12-16 23:02:17 +04:00
|
|
|
"_NET_WM_STATE_FULLSCREEN",
|
2013-12-13 18:40:52 +04:00
|
|
|
"_NET_WM_STATE_DEMANDS_ATTENTION",
|
2015-08-24 17:56:10 +03:00
|
|
|
"_CWM_WM_STATE_FREEZE",
|
2013-07-15 18:50:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
conf_atoms(void)
|
|
|
|
{
|
|
|
|
XInternAtoms(X_Dpy, cwmhints, nitems(cwmhints), False, cwmh);
|
|
|
|
XInternAtoms(X_Dpy, ewmhints, nitems(ewmhints), False, ewmh);
|
|
|
|
}
|