2007-04-27 11:58:48 -06:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
|
|
*
|
2008-01-11 09:06:44 -07: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.
|
|
|
|
*
|
2013-01-08 08:16:04 -07:00
|
|
|
* $OpenBSD: conf.c,v 1.121 2013/01/08 15:16:05 okan Exp $
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2012-11-08 20:52:02 -07:00
|
|
|
#include <stdio.h>
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void conf_mouseunbind(struct conf *, struct mousebinding *);
|
|
|
|
static void conf_unbind(struct conf *, struct keybinding *);
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
/* Add an command menu entry to the end of the menu */
|
|
|
|
void
|
2012-12-19 08:21:34 -07:00
|
|
|
conf_cmd_add(struct conf *c, char *image, char *label)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
|
|
|
/* "term" and "lock" have special meanings. */
|
|
|
|
|
2008-06-04 18:07:05 -06:00
|
|
|
if (strcmp(label, "term") == 0)
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(c->termpath, image, sizeof(c->termpath));
|
2008-06-04 18:07:05 -06:00
|
|
|
else if (strcmp(label, "lock") == 0)
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(c->lockpath, image, sizeof(c->lockpath));
|
2008-06-04 18:07:05 -06:00
|
|
|
else {
|
2009-06-19 18:22:39 -06:00
|
|
|
struct cmd *cmd = xmalloc(sizeof(*cmd));
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(cmd->image, image, sizeof(cmd->image));
|
|
|
|
(void)strlcpy(cmd->label, label, sizeof(cmd->label));
|
2007-04-27 11:58:48 -06:00
|
|
|
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 20:04:50 -07:00
|
|
|
void
|
|
|
|
conf_gap(struct conf *c, struct screen_ctx *sc)
|
|
|
|
{
|
|
|
|
sc->gap = c->gap;
|
|
|
|
}
|
|
|
|
|
2008-06-14 20:47:46 -06:00
|
|
|
void
|
2009-12-08 09:52:17 -07:00
|
|
|
conf_font(struct conf *c, struct screen_ctx *sc)
|
2008-06-14 20:47:46 -06:00
|
|
|
{
|
2012-12-16 19:53:29 -07:00
|
|
|
font_init(sc, c->font, (const char **)c->menucolor);
|
2008-06-14 20:47:46 -06:00
|
|
|
}
|
|
|
|
|
2012-12-16 19:28:45 -07:00
|
|
|
static char *menu_color_binds[CWM_COLOR_MENU_MAX] = {
|
2013-01-04 09:23:51 -07:00
|
|
|
"black", /* CWM_COLOR_MENU_FG */
|
|
|
|
"white", /* CWM_COLOR_MENU_BG */
|
|
|
|
"black", /* CWM_COLOR_MENU_FONT */
|
|
|
|
"", /* CWM_COLOR_MENU_FONT_SEL */
|
2012-12-16 19:28:45 -07:00
|
|
|
};
|
|
|
|
|
2013-01-04 09:27:58 -07:00
|
|
|
static char *color_binds[CWM_COLOR_BORDER_MAX] = {
|
2013-01-04 09:23:51 -07:00
|
|
|
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
|
|
|
|
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
|
|
|
|
"blue", /* CWM_COLOR_BORDER_GROUP */
|
|
|
|
"red", /* CWM_COLOR_BORDER_UNGROUP */
|
2011-09-03 03:25:39 -06:00
|
|
|
};
|
|
|
|
|
2009-05-17 17:40:57 -06:00
|
|
|
void
|
2009-12-08 09:52:17 -07:00
|
|
|
conf_color(struct conf *c, struct screen_ctx *sc)
|
2009-05-17 17:40:57 -06:00
|
|
|
{
|
2009-12-08 09:52:17 -07:00
|
|
|
int i;
|
2009-05-17 17:40:57 -06:00
|
|
|
|
2013-01-04 09:27:58 -07:00
|
|
|
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
2013-01-04 09:23:04 -07:00
|
|
|
sc->color[i] = xu_getcolor(sc, c->color[i]);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2009-08-25 06:05:11 -06:00
|
|
|
static struct {
|
2009-08-24 19:42:05 -06:00
|
|
|
char *key;
|
|
|
|
char *func;
|
|
|
|
} kb_binds[] = {
|
|
|
|
{ "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" },
|
|
|
|
{ "CM-f", "maximize" },
|
|
|
|
{ "CM-equal", "vmaximize" },
|
|
|
|
{ "CMS-equal", "hmaximize" },
|
2011-05-07 11:15:37 -06:00
|
|
|
{ "CMS-f", "freeze" },
|
2012-10-31 13:30:19 -06:00
|
|
|
{ "CMS-r", "restart" },
|
2009-08-24 19:42:05 -06:00
|
|
|
{ "CMS-q", "quit" },
|
|
|
|
{ "M-h", "moveleft" },
|
|
|
|
{ "M-j", "movedown" },
|
|
|
|
{ "M-k", "moveup" },
|
|
|
|
{ "M-l", "moveright" },
|
|
|
|
{ "M-H", "bigmoveleft" },
|
|
|
|
{ "M-J", "bigmovedown" },
|
|
|
|
{ "M-K", "bigmoveup" },
|
|
|
|
{ "M-L", "bigmoveright" },
|
|
|
|
{ "CM-h", "resizeleft" },
|
|
|
|
{ "CM-j", "resizedown" },
|
|
|
|
{ "CM-k", "resizeup" },
|
|
|
|
{ "CM-l", "resizeright" },
|
|
|
|
{ "CM-H", "bigresizeleft" },
|
|
|
|
{ "CM-J", "bigresizedown" },
|
|
|
|
{ "CM-K", "bigresizeup" },
|
|
|
|
{ "CM-L", "bigresizeright" },
|
|
|
|
{ "C-Left", "ptrmoveleft" },
|
|
|
|
{ "C-Down", "ptrmovedown" },
|
|
|
|
{ "C-Up", "ptrmoveup" },
|
|
|
|
{ "C-Right", "ptrmoveright" },
|
|
|
|
{ "CS-Left", "bigptrmoveleft" },
|
|
|
|
{ "CS-Down", "bigptrmovedown" },
|
|
|
|
{ "CS-Up", "bigptrmoveup" },
|
|
|
|
{ "CS-Right", "bigptrmoveright" },
|
|
|
|
},
|
|
|
|
m_binds[] = {
|
|
|
|
{ "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 11:58:48 -06:00
|
|
|
void
|
2008-03-23 09:09:21 -06:00
|
|
|
conf_init(struct conf *c)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2009-08-24 19:42:05 -06:00
|
|
|
int i;
|
|
|
|
|
2012-12-17 17:14:41 -07:00
|
|
|
bzero(c, sizeof(*c));
|
|
|
|
|
2009-01-21 08:04:38 -07:00
|
|
|
c->bwidth = CONF_BWIDTH;
|
2009-02-07 14:07:00 -07:00
|
|
|
c->mamount = CONF_MAMOUNT;
|
2011-06-24 00:06:24 -06:00
|
|
|
c->snapdist = CONF_SNAPDIST;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
TAILQ_INIT(&c->ignoreq);
|
|
|
|
TAILQ_INIT(&c->cmdq);
|
2008-04-15 14:24:41 -06:00
|
|
|
TAILQ_INIT(&c->keybindingq);
|
2008-03-23 09:09:21 -06:00
|
|
|
TAILQ_INIT(&c->autogroupq);
|
2008-06-14 15:48:54 -06:00
|
|
|
TAILQ_INIT(&c->mousebindingq);
|
2007-11-19 15:18:16 -07:00
|
|
|
|
2011-03-22 04:57:31 -06:00
|
|
|
for (i = 0; i < nitems(kb_binds); i++)
|
2009-08-24 19:42:05 -06:00
|
|
|
conf_bindname(c, kb_binds[i].key, kb_binds[i].func);
|
|
|
|
|
2011-03-22 04:57:31 -06:00
|
|
|
for (i = 0; i < nitems(m_binds); i++)
|
2009-08-24 19:42:05 -06:00
|
|
|
conf_mousebind(c, m_binds[i].key, m_binds[i].func);
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2011-09-03 03:25:39 -06:00
|
|
|
for (i = 0; i < nitems(color_binds); i++)
|
2013-01-04 09:23:04 -07:00
|
|
|
c->color[i] = xstrdup(color_binds[i]);
|
2011-09-03 03:25:39 -06:00
|
|
|
|
2012-12-16 19:28:45 -07:00
|
|
|
for (i = 0; i < nitems(menu_color_binds); i++)
|
|
|
|
c->menucolor[i] = xstrdup(menu_color_binds[i]);
|
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
/* Default term/lock */
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
|
|
|
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2012-12-17 16:54:57 -07:00
|
|
|
(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
|
|
|
|
homedir, ".ssh/known_hosts");
|
|
|
|
|
2011-09-03 03:17:16 -06:00
|
|
|
c->font = xstrdup(CONF_FONT);
|
2008-03-23 09:09:21 -06:00
|
|
|
}
|
|
|
|
|
2009-01-23 12:00:59 -07:00
|
|
|
void
|
|
|
|
conf_clear(struct conf *c)
|
|
|
|
{
|
|
|
|
struct autogroupwin *ag;
|
|
|
|
struct keybinding *kb;
|
|
|
|
struct winmatch *wm;
|
|
|
|
struct cmd *cmd;
|
|
|
|
struct mousebinding *mb;
|
2009-05-17 17:40:57 -06:00
|
|
|
int i;
|
2009-01-23 12:00:59 -07:00
|
|
|
|
|
|
|
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->cmdq, cmd, entry);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(cmd);
|
2009-01-23 12:00:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->keybindingq, kb, entry);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(kb);
|
2009-01-23 12:00:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((ag = TAILQ_FIRST(&c->autogroupq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->autogroupq, ag, entry);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(ag->class);
|
|
|
|
free(ag->name);
|
|
|
|
free(ag);
|
2009-01-23 12:00:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((wm = TAILQ_FIRST(&c->ignoreq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->ignoreq, wm, entry);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(wm);
|
2009-01-23 12:00:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(mb);
|
2009-01-23 12:00:59 -07:00
|
|
|
}
|
|
|
|
|
2013-01-04 09:27:58 -07:00
|
|
|
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
2013-01-04 09:23:04 -07:00
|
|
|
free(c->color[i]);
|
2009-05-17 17:40:57 -06:00
|
|
|
|
2012-11-07 13:34:39 -07:00
|
|
|
free(c->font);
|
2009-01-23 12:00:59 -07:00
|
|
|
}
|
|
|
|
|
2008-05-18 13:43:50 -06:00
|
|
|
void
|
|
|
|
conf_client(struct client_ctx *cc)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2008-05-18 13:43:50 -06:00
|
|
|
struct winmatch *wm;
|
|
|
|
char *wname = cc->name;
|
|
|
|
int ignore = 0;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-05-29 18:30:27 -06:00
|
|
|
TAILQ_FOREACH(wm, &Conf.ignoreq, entry) {
|
|
|
|
if (strncasecmp(wm->title, wname, strlen(wm->title)) == 0) {
|
|
|
|
ignore = 1;
|
|
|
|
break;
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
2009-05-29 18:30:27 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-01-21 08:04:38 -07:00
|
|
|
cc->bwidth = ignore ? 0 : Conf.bwidth;
|
2008-05-18 13:43:50 -06:00
|
|
|
cc->flags |= ignore ? CLIENT_IGNORE : 0;
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static struct {
|
2009-01-23 11:58:40 -07:00
|
|
|
char *tag;
|
|
|
|
void (*handler)(struct client_ctx *, union arg *);
|
|
|
|
int flags;
|
|
|
|
union arg argument;
|
2007-04-27 11:58:48 -06:00
|
|
|
} name_to_kbfunc[] = {
|
2009-01-23 11:58:40 -07:00
|
|
|
{ "lower", kbfunc_client_lower, KBFLAG_NEEDCLIENT, {0} },
|
|
|
|
{ "raise", kbfunc_client_raise, KBFLAG_NEEDCLIENT, {0} },
|
|
|
|
{ "search", kbfunc_client_search, 0, {0} },
|
|
|
|
{ "menusearch", kbfunc_menu_search, 0, {0} },
|
|
|
|
{ "hide", kbfunc_client_hide, KBFLAG_NEEDCLIENT, {0} },
|
|
|
|
{ "cycle", kbfunc_client_cycle, 0, {.i = CWM_CYCLE} },
|
|
|
|
{ "rcycle", kbfunc_client_cycle, 0, {.i = CWM_RCYCLE} },
|
|
|
|
{ "label", kbfunc_client_label, KBFLAG_NEEDCLIENT, {0} },
|
|
|
|
{ "delete", kbfunc_client_delete, KBFLAG_NEEDCLIENT, {0} },
|
|
|
|
{ "group1", kbfunc_client_group, 0, {.i = 1} },
|
|
|
|
{ "group2", kbfunc_client_group, 0, {.i = 2} },
|
|
|
|
{ "group3", kbfunc_client_group, 0, {.i = 3} },
|
|
|
|
{ "group4", kbfunc_client_group, 0, {.i = 4} },
|
|
|
|
{ "group5", kbfunc_client_group, 0, {.i = 5} },
|
|
|
|
{ "group6", kbfunc_client_group, 0, {.i = 6} },
|
|
|
|
{ "group7", kbfunc_client_group, 0, {.i = 7} },
|
|
|
|
{ "group8", kbfunc_client_group, 0, {.i = 8} },
|
|
|
|
{ "group9", kbfunc_client_group, 0, {.i = 9} },
|
2009-05-14 10:24:04 -06:00
|
|
|
{ "grouponly1", kbfunc_client_grouponly, 0, {.i = 1} },
|
|
|
|
{ "grouponly2", kbfunc_client_grouponly, 0, {.i = 2} },
|
|
|
|
{ "grouponly3", kbfunc_client_grouponly, 0, {.i = 3} },
|
|
|
|
{ "grouponly4", kbfunc_client_grouponly, 0, {.i = 4} },
|
|
|
|
{ "grouponly5", kbfunc_client_grouponly, 0, {.i = 5} },
|
|
|
|
{ "grouponly6", kbfunc_client_grouponly, 0, {.i = 6} },
|
|
|
|
{ "grouponly7", kbfunc_client_grouponly, 0, {.i = 7} },
|
|
|
|
{ "grouponly8", kbfunc_client_grouponly, 0, {.i = 8} },
|
|
|
|
{ "grouponly9", kbfunc_client_grouponly, 0, {.i = 9} },
|
2009-05-17 11:04:59 -06:00
|
|
|
{ "movetogroup1", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 1} },
|
|
|
|
{ "movetogroup2", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 2} },
|
|
|
|
{ "movetogroup3", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 3} },
|
|
|
|
{ "movetogroup4", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 4} },
|
|
|
|
{ "movetogroup5", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 5} },
|
|
|
|
{ "movetogroup6", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 6} },
|
|
|
|
{ "movetogroup7", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 7} },
|
|
|
|
{ "movetogroup8", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 8} },
|
|
|
|
{ "movetogroup9", kbfunc_client_movetogroup, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = 9} },
|
2009-01-23 11:58:40 -07:00
|
|
|
{ "nogroup", kbfunc_client_nogroup, 0, {0} },
|
2011-06-23 23:30:42 -06:00
|
|
|
{ "cyclegroup", kbfunc_client_cyclegroup, 0, {.i = CWM_CYCLE} },
|
|
|
|
{ "rcyclegroup", kbfunc_client_cyclegroup, 0, {.i = CWM_RCYCLE} },
|
2012-05-09 18:39:47 -06:00
|
|
|
{ "cycleingroup", kbfunc_client_cycle, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = CWM_CYCLE|CWM_INGROUP} },
|
|
|
|
{ "rcycleingroup", kbfunc_client_cycle, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = CWM_RCYCLE|CWM_INGROUP} },
|
2009-01-23 11:58:40 -07:00
|
|
|
{ "grouptoggle", kbfunc_client_grouptoggle, KBFLAG_NEEDCLIENT, {0}},
|
|
|
|
{ "maximize", kbfunc_client_maximize, KBFLAG_NEEDCLIENT, {0} },
|
|
|
|
{ "vmaximize", kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, {0} },
|
2009-08-24 17:54:41 -06:00
|
|
|
{ "hmaximize", kbfunc_client_hmaximize, KBFLAG_NEEDCLIENT, {0} },
|
2011-05-07 11:15:37 -06:00
|
|
|
{ "freeze", kbfunc_client_freeze, KBFLAG_NEEDCLIENT, {0} },
|
2012-10-31 13:30:19 -06:00
|
|
|
{ "restart", kbfunc_restart, 0, {0} },
|
2009-01-23 11:58:40 -07:00
|
|
|
{ "quit", kbfunc_quit_wm, 0, {0} },
|
|
|
|
{ "exec", kbfunc_exec, 0, {.i = CWM_EXEC_PROGRAM} },
|
|
|
|
{ "exec_wm", kbfunc_exec, 0, {.i = CWM_EXEC_WM} },
|
|
|
|
{ "ssh", kbfunc_ssh, 0, {0} },
|
|
|
|
{ "terminal", kbfunc_term, 0, {0} },
|
|
|
|
{ "lock", kbfunc_lock, 0, {0} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "moveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_UP|CWM_MOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "movedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_DOWN|CWM_MOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "moveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_RIGHT|CWM_MOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "moveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_LEFT|CWM_MOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigmoveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_UP|CWM_MOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigmovedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_DOWN|CWM_MOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigmoveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_RIGHT|CWM_MOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigmoveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_LEFT|CWM_MOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "resizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_UP|CWM_RESIZE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "resizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_DOWN|CWM_RESIZE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "resizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_RIGHT|CWM_RESIZE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "resizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_LEFT|CWM_RESIZE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigresizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_UP|CWM_RESIZE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigresizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_DOWN|CWM_RESIZE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigresizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_RIGHT|CWM_RESIZE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigresizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_LEFT|CWM_RESIZE|CWM_BIGMOVE)} },
|
|
|
|
{ "ptrmoveup", kbfunc_moveresize, 0, {.i = (CWM_UP|CWM_PTRMOVE)} },
|
|
|
|
{ "ptrmovedown", kbfunc_moveresize, 0, {.i = (CWM_DOWN|CWM_PTRMOVE)} },
|
|
|
|
{ "ptrmoveleft", kbfunc_moveresize, 0, {.i = (CWM_LEFT|CWM_PTRMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "ptrmoveright", kbfunc_moveresize, 0,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_RIGHT|CWM_PTRMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigptrmoveup", kbfunc_moveresize, 0,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_UP|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigptrmovedown", kbfunc_moveresize, 0,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_DOWN|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigptrmoveleft", kbfunc_moveresize, 0,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
2008-04-16 07:47:29 -06:00
|
|
|
{ "bigptrmoveright", kbfunc_moveresize, 0,
|
2009-01-23 11:58:40 -07:00
|
|
|
{.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} },
|
2013-01-08 08:16:04 -07:00
|
|
|
{ "htile", kbfunc_tile, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = CWM_TILE_HORIZ } },
|
|
|
|
{ "vtile", kbfunc_tile, KBFLAG_NEEDCLIENT,
|
|
|
|
{.i = CWM_TILE_VERT } },
|
2007-04-27 11:58:48 -06:00
|
|
|
};
|
|
|
|
|
2008-07-22 14:51:54 -06:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2009-08-25 06:05:11 -06:00
|
|
|
static struct {
|
2009-08-24 19:44:39 -06:00
|
|
|
char chr;
|
|
|
|
int mask;
|
|
|
|
} bind_mods[] = {
|
|
|
|
{ 'C', ControlMask },
|
|
|
|
{ 'M', Mod1Mask },
|
|
|
|
{ '4', Mod4Mask },
|
|
|
|
{ 'S', ShiftMask },
|
|
|
|
};
|
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
void
|
|
|
|
conf_bindname(struct conf *c, char *name, char *binding)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct keybinding *current_binding;
|
2009-08-24 19:44:39 -06:00
|
|
|
char *substring, *tmp;
|
2012-11-14 14:31:53 -07:00
|
|
|
int i;
|
2007-11-07 15:00:26 -07:00
|
|
|
|
2009-06-19 18:22:39 -06:00
|
|
|
current_binding = xcalloc(1, sizeof(*current_binding));
|
2007-11-07 15:00:26 -07:00
|
|
|
|
2009-08-24 19:44:39 -06:00
|
|
|
if ((substring = strchr(name, '-')) != NULL) {
|
2012-11-14 14:31:53 -07:00
|
|
|
for (i = 0; i < nitems(bind_mods); i++) {
|
|
|
|
if ((tmp = strchr(name, bind_mods[i].chr)) !=
|
2009-08-24 19:44:39 -06:00
|
|
|
NULL && tmp < substring) {
|
2012-11-14 14:31:53 -07:00
|
|
|
current_binding->modmask |= bind_mods[i].mask;
|
2009-08-24 19:44:39 -06:00
|
|
|
}
|
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2009-08-24 19:44:39 -06:00
|
|
|
/* skip past the modifiers */
|
|
|
|
substring++;
|
2012-11-07 14:10:32 -07:00
|
|
|
} else
|
2007-11-13 16:26:04 -07:00
|
|
|
substring = name;
|
|
|
|
|
|
|
|
if (substring[0] == '[' &&
|
|
|
|
substring[strlen(substring)-1] == ']') {
|
|
|
|
sscanf(substring, "[%d]", ¤t_binding->keycode);
|
|
|
|
current_binding->keysym = NoSymbol;
|
|
|
|
} else {
|
|
|
|
current_binding->keycode = 0;
|
|
|
|
current_binding->keysym = XStringToKeysym(substring);
|
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
if (current_binding->keysym == NoSymbol &&
|
2008-04-15 14:24:41 -06:00
|
|
|
current_binding->keycode == 0) {
|
2012-11-07 13:34:39 -07:00
|
|
|
free(current_binding);
|
2007-11-13 16:26:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-19 15:18:16 -07:00
|
|
|
/* We now have the correct binding, remove duplicates. */
|
2008-04-15 14:24:41 -06:00
|
|
|
conf_unbind(c, current_binding);
|
2007-11-19 15:18:16 -07:00
|
|
|
|
2012-11-07 13:37:55 -07:00
|
|
|
if (strcmp("unmap", binding) == 0) {
|
|
|
|
free(current_binding);
|
2007-11-19 15:18:16 -07:00
|
|
|
return;
|
2012-11-07 13:37:55 -07:00
|
|
|
}
|
2007-11-19 15:18:16 -07:00
|
|
|
|
2012-11-14 14:31:53 -07:00
|
|
|
for (i = 0; i < nitems(name_to_kbfunc); i++) {
|
|
|
|
if (strcmp(name_to_kbfunc[i].tag, binding) != 0)
|
2007-04-27 11:58:48 -06:00
|
|
|
continue;
|
|
|
|
|
2012-11-14 14:31:53 -07:00
|
|
|
current_binding->callback = name_to_kbfunc[i].handler;
|
|
|
|
current_binding->flags = name_to_kbfunc[i].flags;
|
|
|
|
current_binding->argument = name_to_kbfunc[i].argument;
|
2013-01-01 07:33:52 -07:00
|
|
|
current_binding->argtype |= ARG_INT;
|
2008-07-22 14:51:54 -06:00
|
|
|
conf_grab(c, current_binding);
|
2007-04-27 11:58:48 -06:00
|
|
|
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
2007-11-13 16:26:04 -07:00
|
|
|
return;
|
2008-05-18 13:47:19 -06:00
|
|
|
}
|
2007-11-13 16:26:04 -07:00
|
|
|
|
|
|
|
current_binding->callback = kbfunc_cmdexec;
|
|
|
|
current_binding->flags = 0;
|
2013-01-01 07:33:52 -07:00
|
|
|
current_binding->argument.c = xstrdup(binding);
|
|
|
|
current_binding->argtype |= ARG_CHAR;
|
2008-07-22 14:51:54 -06:00
|
|
|
conf_grab(c, current_binding);
|
2007-11-13 16:26:04 -07:00
|
|
|
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void
|
2008-07-22 14:51:54 -06:00
|
|
|
conf_unbind(struct conf *c, struct keybinding *unbind)
|
2007-11-19 15:18:16 -07:00
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct keybinding *key = NULL, *keynxt;
|
2008-05-18 13:47:19 -06:00
|
|
|
|
2012-11-07 14:01:48 -07:00
|
|
|
TAILQ_FOREACH_SAFE(key, &c->keybindingq, entry, keynxt) {
|
2007-11-19 15:18:16 -07:00
|
|
|
if (key->modmask != unbind->modmask)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((key->keycode != 0 && key->keysym == NoSymbol &&
|
2008-05-15 16:18:00 -06:00
|
|
|
key->keycode == unbind->keycode) ||
|
2008-05-18 13:47:19 -06:00
|
|
|
key->keysym == unbind->keysym) {
|
2008-07-22 14:51:54 -06:00
|
|
|
conf_ungrab(c, key);
|
2007-11-19 15:18:16 -07:00
|
|
|
TAILQ_REMOVE(&c->keybindingq, key, entry);
|
2013-01-01 07:33:52 -07:00
|
|
|
if (key->argtype & ARG_CHAR)
|
|
|
|
free(key->argument.c);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(key);
|
2008-05-18 13:47:19 -06:00
|
|
|
}
|
2007-11-19 15:18:16 -07:00
|
|
|
}
|
|
|
|
}
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static struct {
|
2008-06-14 15:48:54 -06:00
|
|
|
char *tag;
|
|
|
|
void (*handler)(struct client_ctx *, void *);
|
|
|
|
int context;
|
|
|
|
} name_to_mousefunc[] = {
|
|
|
|
{ "window_move", mousefunc_window_move, MOUSEBIND_CTX_WIN },
|
|
|
|
{ "window_resize", mousefunc_window_resize, MOUSEBIND_CTX_WIN },
|
|
|
|
{ "window_grouptoggle", mousefunc_window_grouptoggle,
|
|
|
|
MOUSEBIND_CTX_WIN },
|
|
|
|
{ "window_lower", mousefunc_window_lower, MOUSEBIND_CTX_WIN },
|
2011-06-24 00:09:26 -06:00
|
|
|
{ "window_raise", mousefunc_window_raise, MOUSEBIND_CTX_WIN },
|
2008-06-25 16:44:42 -06:00
|
|
|
{ "window_hide", mousefunc_window_hide, MOUSEBIND_CTX_WIN },
|
2008-06-14 15:48:54 -06:00
|
|
|
{ "menu_group", mousefunc_menu_group, MOUSEBIND_CTX_ROOT },
|
|
|
|
{ "menu_unhide", mousefunc_menu_unhide, MOUSEBIND_CTX_ROOT },
|
|
|
|
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT },
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
conf_mousebind(struct conf *c, char *name, char *binding)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct mousebinding *current_binding;
|
2009-08-24 19:44:39 -06:00
|
|
|
char *substring, *tmp;
|
2008-07-11 08:21:28 -06:00
|
|
|
const char *errstr;
|
2012-11-14 14:31:53 -07:00
|
|
|
int i;
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2009-06-19 18:22:39 -06:00
|
|
|
current_binding = xcalloc(1, sizeof(*current_binding));
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2009-08-24 19:44:39 -06:00
|
|
|
if ((substring = strchr(name, '-')) != NULL) {
|
2012-11-14 14:31:53 -07:00
|
|
|
for (i = 0; i < nitems(bind_mods); i++) {
|
|
|
|
if ((tmp = strchr(name, bind_mods[i].chr)) !=
|
2009-08-24 19:44:39 -06:00
|
|
|
NULL && tmp < substring) {
|
2012-11-14 14:31:53 -07:00
|
|
|
current_binding->modmask |= bind_mods[i].mask;
|
2009-08-24 19:44:39 -06:00
|
|
|
}
|
|
|
|
}
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2009-08-24 19:44:39 -06:00
|
|
|
/* skip past the modifiers */
|
|
|
|
substring++;
|
|
|
|
} else
|
2008-06-14 15:48:54 -06:00
|
|
|
substring = name;
|
|
|
|
|
2008-06-14 15:59:09 -06:00
|
|
|
current_binding->button = strtonum(substring, 1, 3, &errstr);
|
2008-06-14 15:48:54 -06:00
|
|
|
if (errstr)
|
|
|
|
warnx("number of buttons is %s: %s", errstr, substring);
|
|
|
|
|
2012-11-07 14:04:55 -07:00
|
|
|
/* We now have the correct binding, remove duplicates. */
|
2008-06-14 15:48:54 -06:00
|
|
|
conf_mouseunbind(c, current_binding);
|
|
|
|
|
2012-11-07 13:37:55 -07:00
|
|
|
if (strcmp("unmap", binding) == 0) {
|
|
|
|
free(current_binding);
|
2008-06-14 15:48:54 -06:00
|
|
|
return;
|
2012-11-07 13:37:55 -07:00
|
|
|
}
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2012-11-14 14:31:53 -07:00
|
|
|
for (i = 0; i < nitems(name_to_mousefunc); i++) {
|
|
|
|
if (strcmp(name_to_mousefunc[i].tag, binding) != 0)
|
2008-06-14 15:48:54 -06:00
|
|
|
continue;
|
|
|
|
|
2012-11-14 14:31:53 -07:00
|
|
|
current_binding->context = name_to_mousefunc[i].context;
|
|
|
|
current_binding->callback = name_to_mousefunc[i].handler;
|
2008-06-14 15:48:54 -06:00
|
|
|
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-26 06:21:58 -06:00
|
|
|
static void
|
2008-06-14 15:48:54 -06:00
|
|
|
conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct mousebinding *mb = NULL, *mbnxt;
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2012-11-07 14:01:48 -07:00
|
|
|
TAILQ_FOREACH_SAFE(mb, &c->mousebindingq, entry, mbnxt) {
|
2008-06-14 15:48:54 -06:00
|
|
|
if (mb->modmask != unbind->modmask)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mb->button == unbind->button) {
|
|
|
|
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
2012-11-07 13:34:39 -07:00
|
|
|
free(mb);
|
2008-06-14 15:48:54 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:37:29 -06:00
|
|
|
/*
|
|
|
|
* Grab the mouse buttons that we need for bindings for this client
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
conf_grab_mouse(struct client_ctx *cc)
|
|
|
|
{
|
|
|
|
struct mousebinding *mb;
|
|
|
|
int button;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
|
|
|
if (mb->context != MOUSEBIND_CTX_WIN)
|
2012-05-13 09:15:54 -06:00
|
|
|
continue;
|
2008-06-25 16:37:29 -06:00
|
|
|
|
|
|
|
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");
|
2009-01-08 14:35:19 -07:00
|
|
|
continue;
|
2008-06-25 16:37:29 -06:00
|
|
|
}
|
2009-01-16 08:24:14 -07:00
|
|
|
xu_btn_grab(cc->win, mb->modmask, button);
|
2008-06-25 16:37:29 -06:00
|
|
|
}
|
|
|
|
}
|