2007-04-27 11:58:48 -06:00
|
|
|
/*
|
2011-05-11 07:53:51 -06:00
|
|
|
* calmwm - the calm window manager
|
2008-04-15 14:24:41 -06:00
|
|
|
*
|
2011-05-11 07:53:51 -06:00
|
|
|
* Copyright (c) 2004 Martin Murray <mmurray@monkey.org>
|
2007-04-27 11:58:48 -06:00
|
|
|
*
|
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.
|
|
|
|
*
|
2016-10-06 08:41:19 -06:00
|
|
|
* $OpenBSD: kbfunc.c,v 1.130 2016/10/06 14:41:19 okan Exp $
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
|
2015-01-19 07:54:16 -07:00
|
|
|
#include <sys/types.h>
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
2009-12-14 20:34:34 -07:00
|
|
|
#include <dirent.h>
|
2009-12-14 21:10:42 -07:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2015-01-19 07:54:16 -07:00
|
|
|
#include <limits.h>
|
2007-06-26 13:34:26 -06:00
|
|
|
#include <paths.h>
|
2012-11-07 07:49:46 -07:00
|
|
|
#include <signal.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-06-26 13:34:26 -06:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
#include "calmwm.h"
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
#define HASH_MARKER "|1|"
|
2007-06-26 13:34:26 -06:00
|
|
|
|
2014-01-30 08:41:11 -07:00
|
|
|
extern sig_atomic_t cwm_status;
|
|
|
|
|
2015-11-17 07:32:38 -07:00
|
|
|
static void kbfunc_amount(int, int, unsigned int *, unsigned int *);
|
2015-11-12 11:26:41 -07:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_lower(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2014-01-20 16:18:47 -07:00
|
|
|
client_ptrsave(cc);
|
2007-04-27 11:58:48 -06:00
|
|
|
client_lower(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_raise(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
|
|
|
client_raise(cc);
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:26:41 -07:00
|
|
|
static void
|
2015-11-17 07:32:38 -07:00
|
|
|
kbfunc_amount(int flags, int amt, unsigned int *mx, unsigned int *my)
|
2007-06-27 07:28:22 -06:00
|
|
|
{
|
2015-11-12 11:26:41 -07:00
|
|
|
#define CWM_FACTOR 10
|
2007-06-27 07:28:22 -06:00
|
|
|
|
2015-11-12 11:26:41 -07:00
|
|
|
if (flags & CWM_BIGAMOUNT)
|
|
|
|
amt *= CWM_FACTOR;
|
2007-06-27 07:28:22 -06:00
|
|
|
|
2015-11-12 11:26:41 -07:00
|
|
|
switch (flags & DIRECTIONMASK) {
|
2007-06-27 07:28:22 -06:00
|
|
|
case CWM_UP:
|
2015-11-12 11:26:41 -07:00
|
|
|
*my -= amt;
|
2007-06-27 07:28:22 -06:00
|
|
|
break;
|
2008-04-15 14:24:41 -06:00
|
|
|
case CWM_DOWN:
|
2015-11-12 11:26:41 -07:00
|
|
|
*my += amt;
|
2007-06-27 07:28:22 -06:00
|
|
|
break;
|
|
|
|
case CWM_RIGHT:
|
2015-11-12 11:26:41 -07:00
|
|
|
*mx += amt;
|
2007-06-27 07:28:22 -06:00
|
|
|
break;
|
|
|
|
case CWM_LEFT:
|
2015-11-12 11:26:41 -07:00
|
|
|
*mx -= amt;
|
2007-06-27 07:28:22 -06:00
|
|
|
break;
|
|
|
|
}
|
2015-11-12 11:26:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_ptrmove(struct client_ctx *cc, union arg *arg, int xev)
|
2015-11-12 11:26:41 -07:00
|
|
|
{
|
|
|
|
struct screen_ctx *sc = cc->sc;
|
|
|
|
int x, y;
|
|
|
|
unsigned int mx = 0, my = 0;
|
|
|
|
|
2015-11-17 07:32:38 -07:00
|
|
|
kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
|
2015-11-12 11:26:41 -07:00
|
|
|
|
|
|
|
xu_ptr_getpos(sc->rootwin, &x, &y);
|
|
|
|
xu_ptr_setpos(sc->rootwin, x + mx, y + my);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_move(struct client_ctx *cc, union arg *arg, int xev)
|
2015-11-12 11:26:41 -07:00
|
|
|
{
|
|
|
|
struct screen_ctx *sc = cc->sc;
|
|
|
|
struct geom area;
|
2016-10-03 07:52:17 -06:00
|
|
|
int x, y, px, py;
|
2015-11-12 11:26:41 -07:00
|
|
|
unsigned int mx = 0, my = 0;
|
|
|
|
|
|
|
|
if (cc->flags & CLIENT_FREEZE)
|
|
|
|
return;
|
|
|
|
|
2016-10-03 07:52:17 -06:00
|
|
|
xu_ptr_getpos(cc->win, &px, &py);
|
|
|
|
if (px < 0)
|
|
|
|
px = 0;
|
|
|
|
else if (px > cc->geom.w)
|
|
|
|
px = cc->geom.w;
|
|
|
|
if (py < 0)
|
|
|
|
py = 0;
|
|
|
|
else if (py > cc->geom.h)
|
|
|
|
py = cc->geom.h;
|
|
|
|
|
|
|
|
xu_ptr_setpos(cc->win, px, py);
|
|
|
|
|
2015-11-17 07:32:38 -07:00
|
|
|
kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
|
2015-11-12 11:26:41 -07:00
|
|
|
|
|
|
|
cc->geom.x += mx;
|
|
|
|
if (cc->geom.x + cc->geom.w < 0)
|
|
|
|
cc->geom.x = -cc->geom.w;
|
|
|
|
if (cc->geom.x > sc->view.w - 1)
|
|
|
|
cc->geom.x = sc->view.w - 1;
|
|
|
|
cc->geom.y += my;
|
|
|
|
if (cc->geom.y + cc->geom.h < 0)
|
|
|
|
cc->geom.y = -cc->geom.h;
|
|
|
|
if (cc->geom.y > sc->view.h - 1)
|
|
|
|
cc->geom.y = sc->view.h - 1;
|
|
|
|
|
|
|
|
area = screen_area(sc,
|
|
|
|
cc->geom.x + cc->geom.w / 2,
|
|
|
|
cc->geom.y + cc->geom.h / 2, CWM_GAP);
|
|
|
|
cc->geom.x += client_snapcalc(cc->geom.x,
|
|
|
|
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
|
|
|
|
area.x, area.x + area.w, sc->snapdist);
|
|
|
|
cc->geom.y += client_snapcalc(cc->geom.y,
|
|
|
|
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
|
|
|
|
area.y, area.y + area.h, sc->snapdist);
|
|
|
|
client_move(cc);
|
|
|
|
|
|
|
|
xu_ptr_getpos(cc->win, &x, &y);
|
|
|
|
cc->ptr.x = x + mx;
|
|
|
|
cc->ptr.y = y + my;
|
|
|
|
client_ptrwarp(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_resize(struct client_ctx *cc, union arg *arg, int xev)
|
2015-11-12 11:26:41 -07:00
|
|
|
{
|
|
|
|
unsigned int mx = 0, my = 0;
|
2015-11-17 07:32:38 -07:00
|
|
|
int amt = 1;
|
2015-11-12 11:26:41 -07:00
|
|
|
|
|
|
|
if (cc->flags & CLIENT_FREEZE)
|
|
|
|
return;
|
|
|
|
|
2015-11-17 07:32:38 -07:00
|
|
|
if (!(cc->hint.flags & PResizeInc))
|
|
|
|
amt = Conf.mamount;
|
|
|
|
|
|
|
|
kbfunc_amount(arg->i, amt, &mx, &my);
|
2015-11-12 11:26:41 -07:00
|
|
|
|
2015-11-12 11:33:30 -07:00
|
|
|
if ((cc->geom.w += mx * cc->hint.incw) < cc->hint.minw)
|
|
|
|
cc->geom.w = cc->hint.minw;
|
|
|
|
if ((cc->geom.h += my * cc->hint.inch) < cc->hint.minh)
|
|
|
|
cc->geom.h = cc->hint.minh;
|
2015-11-12 11:26:41 -07:00
|
|
|
client_resize(cc, 1);
|
|
|
|
|
|
|
|
/* Make sure the pointer stays within the window. */
|
|
|
|
xu_ptr_getpos(cc->win, &cc->ptr.x, &cc->ptr.y);
|
|
|
|
if (cc->ptr.x > cc->geom.w)
|
|
|
|
cc->ptr.x = cc->geom.w - cc->bwidth;
|
|
|
|
if (cc->ptr.y > cc->geom.h)
|
|
|
|
cc->ptr.y = cc->geom.h - cc->bwidth;
|
|
|
|
client_ptrwarp(cc);
|
2007-11-13 16:08:49 -07:00
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_menu_client(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2009-12-07 12:44:31 -07:00
|
|
|
struct client_ctx *old_cc;
|
2008-05-19 12:53:09 -06:00
|
|
|
struct menu *mi;
|
2008-07-11 08:21:28 -06:00
|
|
|
struct menu_q menuq;
|
2016-10-06 08:41:19 -06:00
|
|
|
int m = (xev == CWM_BTN);
|
2008-07-11 08:21:28 -06:00
|
|
|
|
|
|
|
old_cc = client_current();
|
2008-04-15 14:24:41 -06:00
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
TAILQ_INIT(&menuq);
|
2016-09-22 08:36:03 -06:00
|
|
|
TAILQ_FOREACH(cc, &sc->clientq, entry) {
|
|
|
|
if (m) {
|
|
|
|
if (cc->flags & CLIENT_HIDDEN)
|
|
|
|
menuq_add(&menuq, cc, NULL);
|
|
|
|
} else
|
|
|
|
menuq_add(&menuq, cc, NULL);
|
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2016-09-22 08:36:03 -06:00
|
|
|
if ((mi = menu_filter(sc, &menuq,
|
|
|
|
(m) ? NULL : "window", NULL,
|
|
|
|
(m) ? CWM_MENU_LIST : 0,
|
2008-05-20 08:50:51 -06:00
|
|
|
search_match_client, search_print_client)) != NULL) {
|
2007-04-27 11:58:48 -06:00
|
|
|
cc = (struct client_ctx *)mi->ctx;
|
|
|
|
if (cc->flags & CLIENT_HIDDEN)
|
|
|
|
client_unhide(cc);
|
2016-10-03 07:41:30 -06:00
|
|
|
else
|
|
|
|
client_raise(cc);
|
2007-04-27 11:58:48 -06:00
|
|
|
if (old_cc)
|
|
|
|
client_ptrsave(old_cc);
|
|
|
|
client_ptrwarp(cc);
|
|
|
|
}
|
|
|
|
|
2012-12-17 07:32:39 -07:00
|
|
|
menuq_clear(&menuq);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2009-12-10 10:16:51 -07:00
|
|
|
struct cmd *cmd;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
2016-10-06 08:41:19 -06:00
|
|
|
int m = (xev == CWM_BTN);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
2015-08-21 10:05:55 -06:00
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
|
|
|
if ((strcmp(cmd->name, "lock") == 0) ||
|
|
|
|
(strcmp(cmd->name, "term") == 0))
|
|
|
|
continue;
|
2015-08-28 06:07:28 -06:00
|
|
|
/* search_match_text() needs mi->text */
|
|
|
|
menuq_add(&menuq, cmd, "%s", cmd->name);
|
2015-08-21 10:05:55 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2016-09-22 08:36:03 -06:00
|
|
|
if ((mi = menu_filter(sc, &menuq,
|
|
|
|
(m) ? NULL : "application", NULL,
|
|
|
|
(m) ? CWM_MENU_LIST : 0,
|
|
|
|
search_match_text, search_print_cmd)) != NULL) {
|
|
|
|
cmd = (struct cmd *)mi->ctx;
|
|
|
|
u_spawn(cmd->path);
|
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
|
2012-12-17 07:32:39 -07:00
|
|
|
menuq_clear(&menuq);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2015-07-12 08:31:47 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_menu_group(struct client_ctx *cc, union arg *arg, int xev)
|
2015-07-12 08:31:47 -06:00
|
|
|
{
|
|
|
|
struct screen_ctx *sc = cc->sc;
|
|
|
|
struct group_ctx *gc;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
2016-10-06 08:41:19 -06:00
|
|
|
int m = (xev == CWM_BTN);
|
2015-07-12 08:31:47 -06:00
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
|
|
|
TAILQ_FOREACH(gc, &sc->groupq, entry) {
|
|
|
|
if (group_holds_only_sticky(gc))
|
|
|
|
continue;
|
|
|
|
menuq_add(&menuq, gc, "%d %s", gc->num, gc->name);
|
|
|
|
}
|
|
|
|
|
2016-09-22 08:36:03 -06:00
|
|
|
if ((mi = menu_filter(sc, &menuq,
|
|
|
|
(m) ? NULL : "group", NULL, CWM_MENU_LIST,
|
2015-07-12 08:31:47 -06:00
|
|
|
search_match_text, search_print_group)) != NULL) {
|
|
|
|
gc = (struct group_ctx *)mi->ctx;
|
|
|
|
(group_holds_only_hidden(gc)) ?
|
|
|
|
group_show(gc) : group_hide(gc);
|
|
|
|
}
|
|
|
|
|
|
|
|
menuq_clear(&menuq);
|
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_cycle(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2015-08-27 12:40:09 -06:00
|
|
|
client_cycle(cc->sc, arg->i);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_hide(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
|
|
|
client_hide(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_exec(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2009-01-23 11:58:40 -07:00
|
|
|
u_spawn(arg->c);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_exec_term(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2014-09-06 10:14:35 -06:00
|
|
|
struct cmd *cmd;
|
|
|
|
|
2014-09-06 12:50:43 -06:00
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
2014-09-06 10:14:35 -06:00
|
|
|
if (strcmp(cmd->name, "term") == 0)
|
|
|
|
u_spawn(cmd->path);
|
2014-09-06 12:50:43 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_exec_lock(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2014-09-06 10:14:35 -06:00
|
|
|
struct cmd *cmd;
|
|
|
|
|
2014-09-06 12:50:43 -06:00
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
2014-09-06 10:14:35 -06:00
|
|
|
if (strcmp(cmd->name, "lock") == 0)
|
|
|
|
u_spawn(cmd->path);
|
2014-09-06 12:50:43 -06:00
|
|
|
}
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2007-04-27 12:08:14 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 12:08:14 -06:00
|
|
|
{
|
2007-09-06 00:01:14 -06:00
|
|
|
#define NPATHS 256
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2014-01-21 08:42:44 -07:00
|
|
|
char **ap, *paths[NPATHS], *path, *pathcpy;
|
2015-01-19 07:54:16 -07:00
|
|
|
char tpath[PATH_MAX];
|
2014-01-21 08:42:44 -07:00
|
|
|
const char *label;
|
2009-12-10 10:16:51 -07:00
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
int l, i, cmd = arg->i;
|
2007-11-28 09:35:52 -07:00
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
switch (cmd) {
|
2015-11-10 13:05:33 -07:00
|
|
|
case CWM_MENU_EXEC:
|
2014-01-22 15:41:09 -07:00
|
|
|
label = "exec";
|
|
|
|
break;
|
2015-11-10 13:05:33 -07:00
|
|
|
case CWM_MENU_EXEC_WM:
|
2014-01-22 15:41:09 -07:00
|
|
|
label = "wm";
|
|
|
|
break;
|
|
|
|
default:
|
2015-11-10 13:05:33 -07:00
|
|
|
errx(1, "kbfunc_menu_exec: invalid cmd %d", cmd);
|
2014-01-22 15:41:09 -07:00
|
|
|
/*NOTREACHED*/
|
2007-11-28 09:35:52 -07:00
|
|
|
}
|
2007-06-26 13:34:26 -06:00
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
2008-04-05 15:09:19 -06:00
|
|
|
|
|
|
|
if ((path = getenv("PATH")) == NULL)
|
|
|
|
path = _PATH_DEFPATH;
|
|
|
|
pathcpy = path = xstrdup(path);
|
|
|
|
|
2007-09-06 00:01:14 -06:00
|
|
|
for (ap = paths; ap < &paths[NPATHS - 1] &&
|
2008-04-05 15:09:19 -06:00
|
|
|
(*ap = strsep(&pathcpy, ":")) != NULL;) {
|
2007-06-26 13:34:26 -06:00
|
|
|
if (**ap != '\0')
|
|
|
|
ap++;
|
|
|
|
}
|
|
|
|
*ap = NULL;
|
2007-09-06 00:01:14 -06:00
|
|
|
for (i = 0; i < NPATHS && paths[i] != NULL; i++) {
|
2007-06-26 13:34:26 -06:00
|
|
|
if ((dirp = opendir(paths[i])) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
/* skip everything but regular files and symlinks */
|
|
|
|
if (dp->d_type != DT_REG && dp->d_type != DT_LNK)
|
|
|
|
continue;
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)memset(tpath, '\0', sizeof(tpath));
|
2007-06-26 13:34:26 -06:00
|
|
|
l = snprintf(tpath, sizeof(tpath), "%s/%s", paths[i],
|
|
|
|
dp->d_name);
|
2014-09-11 10:06:26 -06:00
|
|
|
if (l == -1 || l >= sizeof(tpath))
|
2007-06-26 13:34:26 -06:00
|
|
|
continue;
|
2014-01-20 11:58:03 -07:00
|
|
|
if (access(tpath, X_OK) == 0)
|
|
|
|
menuq_add(&menuq, NULL, "%s", dp->d_name);
|
2007-06-26 13:34:26 -06:00
|
|
|
}
|
2008-07-11 08:21:28 -06:00
|
|
|
(void)closedir(dirp);
|
2007-06-26 13:34:26 -06:00
|
|
|
}
|
2012-11-07 13:34:39 -07:00
|
|
|
free(path);
|
2007-06-26 13:34:26 -06:00
|
|
|
|
2012-11-07 07:39:44 -07:00
|
|
|
if ((mi = menu_filter(sc, &menuq, label, NULL,
|
|
|
|
CWM_MENU_DUMMY | CWM_MENU_FILE,
|
|
|
|
search_match_exec_path, NULL)) != NULL) {
|
2009-09-05 10:06:15 -06:00
|
|
|
if (mi->text[0] == '\0')
|
|
|
|
goto out;
|
2007-11-28 09:35:52 -07:00
|
|
|
switch (cmd) {
|
2015-11-10 13:05:33 -07:00
|
|
|
case CWM_MENU_EXEC:
|
2014-01-22 15:41:09 -07:00
|
|
|
u_spawn(mi->text);
|
|
|
|
break;
|
2015-11-10 13:05:33 -07:00
|
|
|
case CWM_MENU_EXEC_WM:
|
|
|
|
cwm_status = CWM_EXEC_WM;
|
2015-09-16 11:58:25 -06:00
|
|
|
free(wm_argv);
|
|
|
|
wm_argv = xstrdup(mi->text);
|
2014-01-22 15:41:09 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(1, "kb_func: egad, cmd changed value!");
|
|
|
|
break;
|
2007-11-28 09:35:52 -07:00
|
|
|
}
|
|
|
|
}
|
2009-09-05 10:06:15 -06:00
|
|
|
out:
|
2007-06-26 13:34:26 -06:00
|
|
|
if (mi != NULL && mi->dummy)
|
2012-11-07 13:34:39 -07:00
|
|
|
free(mi);
|
2012-12-17 07:32:39 -07:00
|
|
|
menuq_clear(&menuq);
|
2007-06-26 13:34:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg, int xev)
|
2007-06-26 13:34:26 -06:00
|
|
|
{
|
2012-07-04 17:42:03 -06:00
|
|
|
struct screen_ctx *sc = cc->sc;
|
2014-09-06 12:50:43 -06:00
|
|
|
struct cmd *cmd;
|
2009-12-10 10:16:51 -07:00
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
FILE *fp;
|
2012-12-17 16:03:41 -07:00
|
|
|
char *buf, *lbuf, *p;
|
2015-01-19 07:54:16 -07:00
|
|
|
char hostbuf[HOST_NAME_MAX+1];
|
|
|
|
char path[PATH_MAX];
|
2009-12-10 10:16:51 -07:00
|
|
|
int l;
|
|
|
|
size_t len;
|
|
|
|
|
2014-09-06 12:50:43 -06:00
|
|
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
|
|
|
if (strcmp(cmd->name, "term") == 0)
|
2014-09-06 10:14:35 -06:00
|
|
|
break;
|
2014-09-06 12:50:43 -06:00
|
|
|
}
|
2007-06-26 13:34:26 -06:00
|
|
|
TAILQ_INIT(&menuq);
|
2013-04-08 07:02:31 -06:00
|
|
|
|
2015-06-29 08:24:40 -06:00
|
|
|
if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
|
2015-11-10 13:05:33 -07:00
|
|
|
warn("kbfunc_menu_ssh: %s", Conf.known_hosts);
|
2015-06-29 08:24:40 -06:00
|
|
|
goto menu;
|
|
|
|
}
|
|
|
|
|
2007-06-26 13:34:26 -06:00
|
|
|
lbuf = NULL;
|
|
|
|
while ((buf = fgetln(fp, &len))) {
|
|
|
|
if (buf[len - 1] == '\n')
|
|
|
|
buf[len - 1] = '\0';
|
|
|
|
else {
|
|
|
|
/* EOF without EOL, copy and add the NUL */
|
|
|
|
lbuf = xmalloc(len + 1);
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)memcpy(lbuf, buf, len);
|
2007-06-26 13:34:26 -06:00
|
|
|
lbuf[len] = '\0';
|
|
|
|
buf = lbuf;
|
|
|
|
}
|
|
|
|
/* skip hashed hosts */
|
|
|
|
if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
|
|
|
|
continue;
|
|
|
|
for (p = buf; *p != ',' && *p != ' ' && p != buf + len; p++) {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
/* ignore badness */
|
|
|
|
if (p - buf + 1 > sizeof(hostbuf))
|
|
|
|
continue;
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)strlcpy(hostbuf, buf, p - buf + 1);
|
2014-01-20 11:58:03 -07:00
|
|
|
menuq_add(&menuq, NULL, hostbuf);
|
2007-06-26 13:34:26 -06:00
|
|
|
}
|
2012-11-07 13:34:39 -07:00
|
|
|
free(lbuf);
|
2011-07-25 09:10:24 -06:00
|
|
|
(void)fclose(fp);
|
2015-06-29 08:24:40 -06:00
|
|
|
menu:
|
2012-11-07 07:39:44 -07:00
|
|
|
if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY,
|
2008-05-20 08:50:51 -06:00
|
|
|
search_match_exec, NULL)) != NULL) {
|
2009-09-05 10:06:15 -06:00
|
|
|
if (mi->text[0] == '\0')
|
|
|
|
goto out;
|
2014-09-06 12:50:43 -06:00
|
|
|
l = snprintf(path, sizeof(path), "%s -T '[ssh] %s' -e ssh %s",
|
|
|
|
cmd->path, mi->text, mi->text);
|
2014-09-11 10:06:26 -06:00
|
|
|
if (l == -1 || l >= sizeof(path))
|
|
|
|
goto out;
|
|
|
|
u_spawn(path);
|
2007-06-26 13:34:26 -06:00
|
|
|
}
|
2009-09-05 10:06:15 -06:00
|
|
|
out:
|
2007-06-26 13:34:26 -06:00
|
|
|
if (mi != NULL && mi->dummy)
|
2012-11-07 13:34:39 -07:00
|
|
|
free(mi);
|
2012-12-17 07:32:39 -07:00
|
|
|
menuq_clear(&menuq);
|
2007-04-27 12:08:14 -06:00
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_label(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2008-05-20 08:50:51 -06:00
|
|
|
struct menu *mi;
|
|
|
|
struct menu_q menuq;
|
|
|
|
|
|
|
|
TAILQ_INIT(&menuq);
|
2009-11-28 10:52:12 -07:00
|
|
|
|
2010-02-09 18:23:05 -07:00
|
|
|
/* dummy is set, so this will always return */
|
2012-11-07 07:39:44 -07:00
|
|
|
mi = menu_filter(cc->sc, &menuq, "label", cc->label, CWM_MENU_DUMMY,
|
2010-02-09 18:23:05 -07:00
|
|
|
search_match_text, NULL);
|
2008-05-20 08:50:51 -06:00
|
|
|
|
2010-02-09 18:23:05 -07:00
|
|
|
if (!mi->abort) {
|
2012-11-07 13:34:39 -07:00
|
|
|
free(cc->label);
|
2008-05-20 08:50:51 -06:00
|
|
|
cc->label = xstrdup(mi->text);
|
|
|
|
}
|
2012-11-07 13:34:39 -07:00
|
|
|
free(mi);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_delete(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
|
|
|
client_send_delete(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_group_toggle(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2013-01-01 07:19:56 -07:00
|
|
|
group_hidetoggle(cc->sc, arg->i);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2009-05-14 10:24:04 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_group_only(struct client_ctx *cc, union arg *arg, int xev)
|
2009-05-14 10:24:04 -06:00
|
|
|
{
|
2013-01-01 07:19:56 -07:00
|
|
|
group_only(cc->sc, arg->i);
|
2009-05-14 10:24:04 -06:00
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_group_cycle(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2009-12-10 10:16:51 -07:00
|
|
|
group_cycle(cc->sc, arg->i);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2009-12-10 10:16:51 -07:00
|
|
|
group_alltoggle(cc->sc);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
2008-05-19 06:56:58 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg, int xev)
|
2008-05-19 06:56:58 -06:00
|
|
|
{
|
2016-10-06 08:41:19 -06:00
|
|
|
if (xev == CWM_KEY) {
|
2015-08-27 12:40:09 -06:00
|
|
|
/* For X apps that steal events. */
|
2015-05-20 18:37:04 -06:00
|
|
|
XGrabKeyboard(X_Dpy, cc->win, True,
|
|
|
|
GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
}
|
2008-05-19 06:56:58 -06:00
|
|
|
|
2014-09-27 13:04:32 -06:00
|
|
|
group_toggle_membership_enter(cc);
|
2008-05-19 06:56:58 -06:00
|
|
|
}
|
|
|
|
|
2009-05-17 11:04:59 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg, int xev)
|
2009-05-17 11:04:59 -06:00
|
|
|
{
|
2013-01-01 07:19:56 -07:00
|
|
|
group_movetogroup(cc, arg->i);
|
2009-05-17 11:04:59 -06:00
|
|
|
}
|
|
|
|
|
2014-08-25 06:49:19 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_toggle_sticky(struct client_ctx *cc, union arg *arg, int xev)
|
2014-08-25 06:49:19 -06:00
|
|
|
{
|
2014-09-17 12:41:44 -06:00
|
|
|
client_toggle_sticky(cc);
|
2014-08-25 06:49:19 -06:00
|
|
|
}
|
|
|
|
|
2013-12-16 12:02:17 -07:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_toggle_fullscreen(struct client_ctx *cc, union arg *arg, int xev)
|
2013-12-16 12:02:17 -07:00
|
|
|
{
|
2014-09-17 12:41:44 -06:00
|
|
|
client_toggle_fullscreen(cc);
|
2013-12-16 12:02:17 -07:00
|
|
|
}
|
|
|
|
|
2007-04-27 11:58:48 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_toggle_maximize(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2014-09-17 12:41:44 -06:00
|
|
|
client_toggle_maximize(cc);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_toggle_vmaximize(struct client_ctx *cc, union arg *arg, int xev)
|
2007-04-27 11:58:48 -06:00
|
|
|
{
|
2014-09-17 12:41:44 -06:00
|
|
|
client_toggle_vmaximize(cc);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
2008-04-07 17:47:09 -06:00
|
|
|
|
2009-08-24 17:54:41 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_toggle_hmaximize(struct client_ctx *cc, union arg *arg, int xev)
|
2009-08-24 17:54:41 -06:00
|
|
|
{
|
2014-09-17 12:41:44 -06:00
|
|
|
client_toggle_hmaximize(cc);
|
2009-08-24 17:54:41 -06:00
|
|
|
}
|
|
|
|
|
2011-05-07 11:15:37 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_toggle_freeze(struct client_ctx *cc, union arg *arg, int xev)
|
2011-05-07 11:15:37 -06:00
|
|
|
{
|
2014-09-17 12:41:44 -06:00
|
|
|
client_toggle_freeze(cc);
|
2011-05-07 11:15:37 -06:00
|
|
|
}
|
|
|
|
|
2008-04-07 17:47:09 -06:00
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_cwm_status(struct client_ctx *cc, union arg *arg, int xev)
|
2008-07-11 09:18:29 -06:00
|
|
|
{
|
2014-01-22 14:48:27 -07:00
|
|
|
cwm_status = arg->i;
|
2008-07-11 09:18:29 -06:00
|
|
|
}
|
2013-01-08 08:16:04 -07:00
|
|
|
|
|
|
|
void
|
2016-10-06 08:41:19 -06:00
|
|
|
kbfunc_client_tile(struct client_ctx *cc, union arg *arg, int xev)
|
2013-01-08 08:16:04 -07:00
|
|
|
{
|
|
|
|
switch (arg->i) {
|
2015-11-10 13:05:33 -07:00
|
|
|
case CWM_CLIENT_TILE_HORIZ:
|
2014-01-22 15:41:09 -07:00
|
|
|
client_htile(cc);
|
|
|
|
break;
|
2015-11-10 13:05:33 -07:00
|
|
|
case CWM_CLIENT_TILE_VERT:
|
2014-01-22 15:41:09 -07:00
|
|
|
client_vtile(cc);
|
|
|
|
break;
|
2013-01-08 08:16:04 -07:00
|
|
|
}
|
|
|
|
}
|