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.
|
|
|
|
*
|
2009-01-08 14:35:19 -07:00
|
|
|
* $Id: conf.c,v 1.51 2009/01/08 21:35:19 oga Exp $
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "headers.h"
|
|
|
|
#include "calmwm.h"
|
|
|
|
|
|
|
|
#ifndef timespeccmp
|
|
|
|
#define timespeccmp(tsp, usp, cmp) \
|
2008-04-15 14:24:41 -06:00
|
|
|
(((tsp)->tv_sec == (usp)->tv_sec) ? \
|
|
|
|
((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
|
|
|
|
((tsp)->tv_sec cmp (usp)->tv_sec))
|
2007-04-27 11:58:48 -06:00
|
|
|
#endif
|
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
extern struct screen_ctx *Curscreen;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
/* Add an command menu entry to the end of the menu */
|
|
|
|
void
|
|
|
|
conf_cmd_add(struct conf *c, char *image, char *label, int flags)
|
|
|
|
{
|
|
|
|
/* "term" and "lock" have special meanings. */
|
|
|
|
|
2008-06-04 18:07:05 -06:00
|
|
|
if (strcmp(label, "term") == 0)
|
|
|
|
strlcpy(c->termpath, image, sizeof(c->termpath));
|
|
|
|
else if (strcmp(label, "lock") == 0)
|
|
|
|
strlcpy(c->lockpath, image, sizeof(c->lockpath));
|
|
|
|
else {
|
2007-04-27 11:58:48 -06:00
|
|
|
struct cmd *cmd;
|
|
|
|
XMALLOC(cmd, struct cmd);
|
|
|
|
cmd->flags = flags;
|
|
|
|
strlcpy(cmd->image, image, sizeof(cmd->image));
|
|
|
|
strlcpy(cmd->label, label, sizeof(cmd->label));
|
|
|
|
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 20:47:46 -06:00
|
|
|
void
|
|
|
|
conf_font(struct conf *c)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct screen_ctx *sc;
|
|
|
|
|
|
|
|
sc = screen_current();
|
2008-06-14 20:47:46 -06:00
|
|
|
|
|
|
|
c->DefaultFont = font_make(sc, Conf.DefaultFontName);
|
|
|
|
c->FontHeight = font_ascent() + font_descent() + 1;
|
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2008-03-23 09:09:21 -06:00
|
|
|
conf_reload(struct conf *c)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2008-03-23 09:09:21 -06:00
|
|
|
if (parse_config(c->conf_path, c) == -1) {
|
|
|
|
warnx("config file %s has errors, not reloading", c->conf_path);
|
2007-04-27 11:58:48 -06:00
|
|
|
return;
|
2008-03-23 09:09:21 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-06-14 20:47:46 -06:00
|
|
|
conf_font(c);
|
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
|
|
|
{
|
2008-03-23 09:09:21 -06:00
|
|
|
c->flags = 0;
|
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
|
|
|
|
|
|
|
conf_bindname(c, "CM-Return", "terminal");
|
|
|
|
conf_bindname(c, "CM-Delete", "lock");
|
|
|
|
conf_bindname(c, "M-question", "exec");
|
2008-04-07 17:47:09 -06:00
|
|
|
conf_bindname(c, "CM-w", "exec_wm");
|
2007-11-19 15:18:16 -07:00
|
|
|
conf_bindname(c, "M-period", "ssh");
|
|
|
|
conf_bindname(c, "M-Return", "hide");
|
|
|
|
conf_bindname(c, "M-Down", "lower");
|
|
|
|
conf_bindname(c, "M-Up", "raise");
|
|
|
|
conf_bindname(c, "M-slash", "search");
|
|
|
|
conf_bindname(c, "C-slash", "menusearch");
|
|
|
|
conf_bindname(c, "M-Tab", "cycle");
|
|
|
|
conf_bindname(c, "MS-Tab", "rcycle");
|
|
|
|
conf_bindname(c, "CM-n", "label");
|
|
|
|
conf_bindname(c, "CM-x", "delete");
|
2007-11-28 09:02:37 -07:00
|
|
|
conf_bindname(c, "CM-0", "nogroup");
|
2007-11-19 15:18:16 -07:00
|
|
|
conf_bindname(c, "CM-1", "group1");
|
|
|
|
conf_bindname(c, "CM-2", "group2");
|
|
|
|
conf_bindname(c, "CM-3", "group3");
|
2007-11-27 10:17:08 -07:00
|
|
|
conf_bindname(c, "CM-4", "group4");
|
2007-11-19 15:18:16 -07:00
|
|
|
conf_bindname(c, "CM-5", "group5");
|
|
|
|
conf_bindname(c, "CM-6", "group6");
|
|
|
|
conf_bindname(c, "CM-7", "group7");
|
|
|
|
conf_bindname(c, "CM-8", "group8");
|
|
|
|
conf_bindname(c, "CM-9", "group9");
|
2008-05-19 11:11:19 -06:00
|
|
|
conf_bindname(c, "M-Right", "cyclegroup");
|
|
|
|
conf_bindname(c, "M-Left", "rcyclegroup");
|
2008-05-19 06:56:58 -06:00
|
|
|
conf_bindname(c, "CM-g", "grouptoggle");
|
2007-11-19 15:18:16 -07:00
|
|
|
conf_bindname(c, "CM-f", "maximize");
|
|
|
|
conf_bindname(c, "CM-equal", "vmaximize");
|
2008-07-11 09:18:29 -06:00
|
|
|
conf_bindname(c, "CMS-r", "reload");
|
2008-04-08 08:12:28 -06:00
|
|
|
conf_bindname(c, "CMS-q", "quit");
|
2007-11-19 15:18:16 -07:00
|
|
|
|
|
|
|
conf_bindname(c, "M-h", "moveleft");
|
|
|
|
conf_bindname(c, "M-j", "movedown");
|
|
|
|
conf_bindname(c, "M-k", "moveup");
|
|
|
|
conf_bindname(c, "M-l", "moveright");
|
|
|
|
conf_bindname(c, "M-H", "bigmoveleft");
|
|
|
|
conf_bindname(c, "M-J", "bigmovedown");
|
|
|
|
conf_bindname(c, "M-K", "bigmoveup");
|
|
|
|
conf_bindname(c, "M-L", "bigmoveright");
|
|
|
|
|
|
|
|
conf_bindname(c, "CM-h", "resizeleft");
|
|
|
|
conf_bindname(c, "CM-j", "resizedown");
|
|
|
|
conf_bindname(c, "CM-k", "resizeup");
|
|
|
|
conf_bindname(c, "CM-l", "resizeright");
|
|
|
|
conf_bindname(c, "CM-H", "bigresizeleft");
|
|
|
|
conf_bindname(c, "CM-J", "bigresizedown");
|
|
|
|
conf_bindname(c, "CM-K", "bigresizeup");
|
|
|
|
conf_bindname(c, "CM-L", "bigresizeright");
|
|
|
|
|
|
|
|
conf_bindname(c, "C-Left", "ptrmoveleft");
|
|
|
|
conf_bindname(c, "C-Down", "ptrmovedown");
|
|
|
|
conf_bindname(c, "C-Up", "ptrmoveup");
|
|
|
|
conf_bindname(c, "C-Right", "ptrmoveright");
|
|
|
|
conf_bindname(c, "CS-Left", "bigptrmoveleft");
|
|
|
|
conf_bindname(c, "CS-Down", "bigptrmovedown");
|
|
|
|
conf_bindname(c, "CS-Up", "bigptrmoveup");
|
|
|
|
conf_bindname(c, "CS-Right", "bigptrmoveright");
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
conf_mousebind(c, "1", "menu_unhide");
|
|
|
|
conf_mousebind(c, "2", "menu_group");
|
|
|
|
conf_mousebind(c, "3", "menu_cmd");
|
|
|
|
conf_mousebind(c, "M-1", "window_move");
|
|
|
|
conf_mousebind(c, "CM-1", "window_grouptoggle");
|
|
|
|
conf_mousebind(c, "M-2", "window_resize");
|
|
|
|
conf_mousebind(c, "M-3", "window_lower");
|
2008-06-25 16:44:42 -06:00
|
|
|
conf_mousebind(c, "CMS-3", "window_hide");
|
2008-06-14 15:48:54 -06:00
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
/* Default term/lock */
|
|
|
|
strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
|
|
|
strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-06-16 13:09:48 -06:00
|
|
|
c->DefaultFontName = xstrdup(DEFAULTFONTNAME);
|
2008-03-23 09:09:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-05-19 12:53:09 -06:00
|
|
|
conf_setup(struct conf *c, const char *conf_file)
|
2008-03-23 09:09:21 -06:00
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct stat sb;
|
2008-06-14 15:51:00 -06:00
|
|
|
|
2008-05-19 12:53:09 -06:00
|
|
|
if (conf_file == NULL) {
|
2008-03-23 09:09:21 -06:00
|
|
|
char *home = getenv("HOME");
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
if (home == NULL)
|
|
|
|
errx(1, "No HOME directory.");
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s", home,
|
|
|
|
CONFFILE);
|
2008-04-15 14:24:41 -06:00
|
|
|
} else
|
2008-06-14 15:51:00 -06:00
|
|
|
if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG))
|
|
|
|
errx(1, "%s: %s", conf_file, strerror(errno));
|
|
|
|
else
|
2008-07-11 08:24:34 -06:00
|
|
|
strlcpy(c->conf_path, conf_file, sizeof(c->conf_path));
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2008-03-23 09:09:21 -06:00
|
|
|
conf_init(c);
|
|
|
|
|
|
|
|
(void)parse_config(c->conf_path, c);
|
2007-04-27 11:58:48 -06: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
|
|
|
|
|
|
|
/* Can wname be NULL? */
|
|
|
|
if (wname != NULL) {
|
2008-03-23 09:09:21 -06:00
|
|
|
TAILQ_FOREACH(wm, &Conf.ignoreq, entry) {
|
2008-05-18 13:43:50 -06:00
|
|
|
if (strncasecmp(wm->title, wname, strlen(wm->title))
|
|
|
|
== 0) {
|
2007-04-27 11:58:48 -06:00
|
|
|
ignore = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ignore = 1;
|
|
|
|
|
2008-05-18 13:43:50 -06:00
|
|
|
cc->bwidth = ignore ? 0 : 3;
|
|
|
|
cc->flags |= ignore ? CLIENT_IGNORE : 0;
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char *tag;
|
|
|
|
void (*handler)(struct client_ctx *, void *);
|
|
|
|
int flags;
|
|
|
|
void *argument;
|
|
|
|
} name_to_kbfunc[] = {
|
|
|
|
{ "lower", kbfunc_client_lower, KBFLAG_NEEDCLIENT, 0 },
|
|
|
|
{ "raise", kbfunc_client_raise, KBFLAG_NEEDCLIENT, 0 },
|
2007-12-30 19:49:45 -07:00
|
|
|
{ "search", kbfunc_client_search, 0, 0 },
|
2007-11-07 15:00:26 -07:00
|
|
|
{ "menusearch", kbfunc_menu_search, 0, 0 },
|
2007-04-27 11:58:48 -06:00
|
|
|
{ "hide", kbfunc_client_hide, KBFLAG_NEEDCLIENT, 0 },
|
2008-05-19 09:17:50 -06:00
|
|
|
{ "cycle", kbfunc_client_cycle, 0, (void *)CWM_CYCLE },
|
|
|
|
{ "rcycle", kbfunc_client_cycle, 0, (void *)CWM_RCYCLE },
|
2007-04-27 11:58:48 -06:00
|
|
|
{ "label", kbfunc_client_label, KBFLAG_NEEDCLIENT, 0 },
|
|
|
|
{ "delete", kbfunc_client_delete, KBFLAG_NEEDCLIENT, 0 },
|
2007-11-07 15:00:26 -07:00
|
|
|
{ "group1", kbfunc_client_group, 0, (void *)1 },
|
|
|
|
{ "group2", kbfunc_client_group, 0, (void *)2 },
|
|
|
|
{ "group3", kbfunc_client_group, 0, (void *)3 },
|
|
|
|
{ "group4", kbfunc_client_group, 0, (void *)4 },
|
|
|
|
{ "group5", kbfunc_client_group, 0, (void *)5 },
|
|
|
|
{ "group6", kbfunc_client_group, 0, (void *)6 },
|
|
|
|
{ "group7", kbfunc_client_group, 0, (void *)7 },
|
|
|
|
{ "group8", kbfunc_client_group, 0, (void *)8 },
|
|
|
|
{ "group9", kbfunc_client_group, 0, (void *)9 },
|
|
|
|
{ "nogroup", kbfunc_client_nogroup, 0, 0 },
|
2008-05-19 11:11:19 -06:00
|
|
|
{ "cyclegroup", kbfunc_client_cyclegroup, 0, (void *)CWM_CYCLEGROUP },
|
|
|
|
{ "rcyclegroup", kbfunc_client_cyclegroup, 0, (void *)CWM_RCYCLEGROUP },
|
2008-05-19 06:56:58 -06:00
|
|
|
{ "grouptoggle", kbfunc_client_grouptoggle, KBFLAG_NEEDCLIENT, 0},
|
2007-11-07 15:00:26 -07:00
|
|
|
{ "maximize", kbfunc_client_maximize, KBFLAG_NEEDCLIENT, 0 },
|
|
|
|
{ "vmaximize", kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, 0 },
|
2008-07-11 09:18:29 -06:00
|
|
|
{ "reload", kbfunc_reload, 0, 0 },
|
2008-04-07 17:47:09 -06:00
|
|
|
{ "quit", kbfunc_quit_wm, 0, 0 },
|
2008-01-02 18:56:25 -07:00
|
|
|
{ "exec", kbfunc_exec, 0, (void *)CWM_EXEC_PROGRAM },
|
|
|
|
{ "exec_wm", kbfunc_exec, 0, (void *)CWM_EXEC_WM },
|
2007-11-07 15:00:26 -07:00
|
|
|
{ "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,
|
|
|
|
(void *)(CWM_UP|CWM_MOVE) },
|
|
|
|
{ "movedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_DOWN|CWM_MOVE) },
|
|
|
|
{ "moveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_RIGHT|CWM_MOVE) },
|
|
|
|
{ "moveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_LEFT|CWM_MOVE) },
|
|
|
|
{ "bigmoveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_UP|CWM_MOVE|CWM_BIGMOVE) },
|
|
|
|
{ "bigmovedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_DOWN|CWM_MOVE|CWM_BIGMOVE) },
|
|
|
|
{ "bigmoveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_RIGHT|CWM_MOVE|CWM_BIGMOVE) },
|
|
|
|
{ "bigmoveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_LEFT|CWM_MOVE|CWM_BIGMOVE) },
|
|
|
|
{ "resizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_UP|CWM_RESIZE) },
|
|
|
|
{ "resizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_DOWN|CWM_RESIZE) },
|
|
|
|
{ "resizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_RIGHT|CWM_RESIZE) },
|
|
|
|
{ "resizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_LEFT|CWM_RESIZE) },
|
|
|
|
{ "bigresizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_UP|CWM_RESIZE|CWM_BIGMOVE) },
|
|
|
|
{ "bigresizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_DOWN|CWM_RESIZE|CWM_BIGMOVE) },
|
|
|
|
{ "bigresizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_RIGHT|CWM_RESIZE|CWM_BIGMOVE) },
|
|
|
|
{ "bigresizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT,
|
|
|
|
(void *)(CWM_LEFT|CWM_RESIZE|CWM_BIGMOVE) },
|
|
|
|
{ "ptrmoveup", kbfunc_moveresize, 0, (void *)(CWM_UP|CWM_PTRMOVE) },
|
|
|
|
{ "ptrmovedown", kbfunc_moveresize, 0, (void *)(CWM_DOWN|CWM_PTRMOVE) },
|
|
|
|
{ "ptrmoveleft", kbfunc_moveresize, 0, (void *)(CWM_LEFT|CWM_PTRMOVE) },
|
|
|
|
{ "ptrmoveright", kbfunc_moveresize, 0,
|
|
|
|
(void *)(CWM_RIGHT|CWM_PTRMOVE) },
|
|
|
|
{ "bigptrmoveup", kbfunc_moveresize, 0,
|
|
|
|
(void *)(CWM_UP|CWM_PTRMOVE|CWM_BIGMOVE) },
|
|
|
|
{ "bigptrmovedown", kbfunc_moveresize, 0,
|
|
|
|
(void *)(CWM_DOWN|CWM_PTRMOVE|CWM_BIGMOVE) },
|
|
|
|
{ "bigptrmoveleft", kbfunc_moveresize, 0,
|
|
|
|
(void *)(CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE) },
|
|
|
|
{ "bigptrmoveright", kbfunc_moveresize, 0,
|
|
|
|
(void *)(CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE) },
|
2007-04-27 11:58:48 -06:00
|
|
|
{ NULL, NULL, 0, 0},
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
char *substring;
|
|
|
|
int iter;
|
2007-11-07 15:00:26 -07:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
XCALLOC(current_binding, struct keybinding);
|
2007-11-07 15:00:26 -07:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
if (strchr(name, 'C') != NULL &&
|
|
|
|
strchr(name, 'C') < strchr(name, '-'))
|
|
|
|
current_binding->modmask |= ControlMask;
|
2007-11-07 15:00:26 -07:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
if (strchr(name, 'M') != NULL &&
|
2008-04-15 14:24:41 -06:00
|
|
|
strchr(name, 'M') < strchr(name, '-'))
|
2007-11-13 16:26:04 -07:00
|
|
|
current_binding->modmask |= Mod1Mask;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
if (strchr(name, '4') != NULL &&
|
2008-04-15 14:24:41 -06:00
|
|
|
strchr(name, '4') < strchr(name, '-'))
|
2007-11-13 16:26:04 -07:00
|
|
|
current_binding->modmask |= Mod4Mask;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
if (strchr(name, 'S') != NULL &&
|
2008-04-15 14:24:41 -06:00
|
|
|
strchr(name, 'S') < strchr(name, '-'))
|
2007-11-13 16:26:04 -07:00
|
|
|
current_binding->modmask |= ShiftMask;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
substring = strchr(name, '-') + 1;
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
/* If there is no '-' in name, continue as is */
|
|
|
|
if (strchr(name, '-') == NULL)
|
|
|
|
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) {
|
2007-11-13 16:26:04 -07:00
|
|
|
xfree(current_binding);
|
|
|
|
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
|
|
|
|
2008-07-11 08:21:28 -06:00
|
|
|
if (strcmp("unmap", binding) == 0)
|
2007-11-19 15:18:16 -07:00
|
|
|
return;
|
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
for (iter = 0; name_to_kbfunc[iter].tag != NULL; iter++) {
|
|
|
|
if (strcmp(name_to_kbfunc[iter].tag, binding) != 0)
|
2007-04-27 11:58:48 -06:00
|
|
|
continue;
|
|
|
|
|
2007-11-13 16:26:04 -07:00
|
|
|
current_binding->callback = name_to_kbfunc[iter].handler;
|
|
|
|
current_binding->flags = name_to_kbfunc[iter].flags;
|
|
|
|
current_binding->argument = name_to_kbfunc[iter].argument;
|
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;
|
2008-04-16 07:38:09 -06:00
|
|
|
current_binding->argument = xstrdup(binding);
|
2007-11-13 16:26:04 -07:00
|
|
|
current_binding->flags = 0;
|
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);
|
|
|
|
return;
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2008-07-22 14:51:54 -06:00
|
|
|
void
|
|
|
|
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
|
|
|
|
|
|
|
for (key = TAILQ_FIRST(&c->keybindingq);
|
|
|
|
key != TAILQ_END(&c->keybindingq); key = keynxt) {
|
|
|
|
keynxt = TAILQ_NEXT(key, entry);
|
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);
|
2008-05-18 13:47:19 -06:00
|
|
|
xfree(key);
|
|
|
|
}
|
2007-11-19 15:18:16 -07:00
|
|
|
}
|
|
|
|
}
|
2008-06-14 15:48:54 -06:00
|
|
|
|
|
|
|
struct {
|
|
|
|
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 },
|
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 },
|
|
|
|
{ NULL, NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
conf_mousebind(struct conf *c, char *name, char *binding)
|
|
|
|
{
|
2008-07-11 08:21:28 -06:00
|
|
|
struct mousebinding *current_binding;
|
|
|
|
char *substring;
|
|
|
|
const char *errstr;
|
|
|
|
int iter;
|
2008-06-14 15:48:54 -06:00
|
|
|
|
|
|
|
XCALLOC(current_binding, struct mousebinding);
|
|
|
|
|
|
|
|
if (strchr(name, 'C') != NULL &&
|
|
|
|
strchr(name, 'C') < strchr(name, '-'))
|
|
|
|
current_binding->modmask |= ControlMask;
|
|
|
|
|
|
|
|
if (strchr(name, 'M') != NULL &&
|
|
|
|
strchr(name, 'M') < strchr(name, '-'))
|
|
|
|
current_binding->modmask |= Mod1Mask;
|
|
|
|
|
2008-06-25 16:38:36 -06:00
|
|
|
if (strchr(name, 'S') != NULL &&
|
|
|
|
strchr(name, 'S') < strchr(name, '-'))
|
|
|
|
current_binding->modmask |= ShiftMask;
|
|
|
|
|
2008-06-25 16:40:27 -06:00
|
|
|
if (strchr(name, '4') != NULL &&
|
|
|
|
strchr(name, '4') < strchr(name, '-'))
|
|
|
|
current_binding->modmask |= Mod4Mask;
|
|
|
|
|
2008-06-14 15:48:54 -06:00
|
|
|
substring = strchr(name, '-') + 1;
|
|
|
|
|
|
|
|
if (strchr(name, '-') == NULL)
|
|
|
|
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);
|
|
|
|
|
|
|
|
conf_mouseunbind(c, current_binding);
|
|
|
|
|
|
|
|
if (strcmp("unmap", binding) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (iter = 0; name_to_mousefunc[iter].tag != NULL; iter++) {
|
|
|
|
if (strcmp(name_to_mousefunc[iter].tag, binding) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
current_binding->context = name_to_mousefunc[iter].context;
|
|
|
|
current_binding->callback = name_to_mousefunc[iter].handler;
|
|
|
|
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
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
|
|
|
|
|
|
|
for (mb = TAILQ_FIRST(&c->mousebindingq);
|
|
|
|
mb != TAILQ_END(&c->mousebindingq); mb = mbnxt) {
|
|
|
|
mbnxt = TAILQ_NEXT(mb, entry);
|
|
|
|
|
|
|
|
if (mb->modmask != unbind->modmask)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mb->button == unbind->button) {
|
|
|
|
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
|
|
|
xfree(mb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
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");
|
2009-01-08 14:35:19 -07:00
|
|
|
continue;
|
2008-06-25 16:37:29 -06:00
|
|
|
}
|
|
|
|
xu_btn_grab(cc->pwin, mb->modmask, button);
|
|
|
|
}
|
|
|
|
}
|