mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
move the single keycode function directly into the menu code.
ok oga@
This commit is contained in:
parent
e03323d22e
commit
00b502b1da
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@
|
||||||
PROG= cwm
|
PROG= cwm
|
||||||
|
|
||||||
SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \
|
SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \
|
||||||
search.c util.c xutil.c conf.c input.c xevents.c group.c \
|
search.c util.c xutil.c conf.c xevents.c group.c \
|
||||||
kbfunc.c mousefunc.c font.c parse.y
|
kbfunc.c mousefunc.c font.c parse.y
|
||||||
|
|
||||||
CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR}
|
CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR}
|
||||||
|
|
9
calmwm.h
9
calmwm.h
|
@ -325,12 +325,6 @@ struct menu {
|
||||||
|
|
||||||
TAILQ_HEAD(menu_q, menu);
|
TAILQ_HEAD(menu_q, menu);
|
||||||
|
|
||||||
enum ctltype {
|
|
||||||
CTL_NONE = -1,
|
|
||||||
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
|
|
||||||
CTL_ABORT, CTL_ALL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* MWM hints */
|
/* MWM hints */
|
||||||
|
|
||||||
struct mwm_hints {
|
struct mwm_hints {
|
||||||
|
@ -346,9 +340,6 @@ struct mwm_hints {
|
||||||
#define MWM_DECOR_ALL (1 << 0)
|
#define MWM_DECOR_ALL (1 << 0)
|
||||||
#define MWM_DECOR_BORDER (1 << 1)
|
#define MWM_DECOR_BORDER (1 << 1)
|
||||||
|
|
||||||
int input_keycodetrans(KeyCode, u_int, enum ctltype *,
|
|
||||||
char *);
|
|
||||||
|
|
||||||
__dead void usage(void);
|
__dead void usage(void);
|
||||||
|
|
||||||
struct client_ctx *client_find(Window);
|
struct client_ctx *client_find(Window);
|
||||||
|
|
117
input.c
117
input.c
|
@ -1,117 +0,0 @@
|
||||||
/*
|
|
||||||
* calmwm - the calm window manager
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/queue.h>
|
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "calmwm.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
input_keycodetrans(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
|
|
||||||
{
|
|
||||||
int ks;
|
|
||||||
|
|
||||||
*ctl = CTL_NONE;
|
|
||||||
*chr = '\0';
|
|
||||||
|
|
||||||
ks = XKeycodeToKeysym(X_Dpy, kc, (state & ShiftMask) ? 1 : 0);
|
|
||||||
|
|
||||||
/* Look for control characters. */
|
|
||||||
switch (ks) {
|
|
||||||
case XK_BackSpace:
|
|
||||||
*ctl = CTL_ERASEONE;
|
|
||||||
break;
|
|
||||||
case XK_Return:
|
|
||||||
*ctl = CTL_RETURN;
|
|
||||||
break;
|
|
||||||
case XK_Up:
|
|
||||||
*ctl = CTL_UP;
|
|
||||||
break;
|
|
||||||
case XK_Down:
|
|
||||||
*ctl = CTL_DOWN;
|
|
||||||
break;
|
|
||||||
case XK_Escape:
|
|
||||||
*ctl = CTL_ABORT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*ctl == CTL_NONE && (state & ControlMask)) {
|
|
||||||
switch (ks) {
|
|
||||||
case XK_s:
|
|
||||||
case XK_S:
|
|
||||||
/* Emacs "next" */
|
|
||||||
*ctl = CTL_DOWN;
|
|
||||||
break;
|
|
||||||
case XK_r:
|
|
||||||
case XK_R:
|
|
||||||
/* Emacs "previous" */
|
|
||||||
*ctl = CTL_UP;
|
|
||||||
break;
|
|
||||||
case XK_u:
|
|
||||||
case XK_U:
|
|
||||||
*ctl = CTL_WIPE;
|
|
||||||
break;
|
|
||||||
case XK_h:
|
|
||||||
case XK_H:
|
|
||||||
*ctl = CTL_ERASEONE;
|
|
||||||
break;
|
|
||||||
case XK_a:
|
|
||||||
case XK_A:
|
|
||||||
*ctl = CTL_ALL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*ctl == CTL_NONE && (state & Mod1Mask)) {
|
|
||||||
switch (ks) {
|
|
||||||
case XK_j:
|
|
||||||
case XK_J:
|
|
||||||
/* Vi "down" */
|
|
||||||
*ctl = CTL_DOWN;
|
|
||||||
break;
|
|
||||||
case XK_k:
|
|
||||||
case XK_K:
|
|
||||||
/* Vi "up" */
|
|
||||||
*ctl = CTL_UP;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*ctl != CTL_NONE)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* For regular characters, only (part of, actually) Latin 1
|
|
||||||
* for now.
|
|
||||||
*/
|
|
||||||
if (ks < 0x20 || ks > 0x07e)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
*chr = (char)ks;
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
97
menu.c
97
menu.c
|
@ -30,6 +30,12 @@
|
||||||
#define PROMPT_SCHAR '»'
|
#define PROMPT_SCHAR '»'
|
||||||
#define PROMPT_ECHAR '«'
|
#define PROMPT_ECHAR '«'
|
||||||
|
|
||||||
|
enum ctltype {
|
||||||
|
CTL_NONE = -1,
|
||||||
|
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
|
||||||
|
CTL_ABORT, CTL_ALL
|
||||||
|
};
|
||||||
|
|
||||||
struct menu_ctx {
|
struct menu_ctx {
|
||||||
char searchstr[MENU_MAXENTRY + 1];
|
char searchstr[MENU_MAXENTRY + 1];
|
||||||
char dispstr[MENU_MAXENTRY*2 + 1];
|
char dispstr[MENU_MAXENTRY*2 + 1];
|
||||||
|
@ -58,6 +64,8 @@ static void menu_draw(struct screen_ctx *, struct menu_ctx *,
|
||||||
struct menu_q *, struct menu_q *);
|
struct menu_q *, struct menu_q *);
|
||||||
static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *,
|
static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *,
|
||||||
int, int);
|
int, int);
|
||||||
|
static int menu_keycode(KeyCode, u_int, enum ctltype *,
|
||||||
|
char *);
|
||||||
|
|
||||||
void
|
void
|
||||||
menu_init(struct screen_ctx *sc)
|
menu_init(struct screen_ctx *sc)
|
||||||
|
@ -185,8 +193,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
||||||
char chr;
|
char chr;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (input_keycodetrans(e->xkey.keycode, e->xkey.state,
|
if (menu_keycode(e->xkey.keycode, e->xkey.state, &ctl, &chr) < 0)
|
||||||
&ctl, &chr) < 0)
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
switch (ctl) {
|
switch (ctl) {
|
||||||
|
@ -416,3 +423,89 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y)
|
||||||
|
|
||||||
return (entry);
|
return (entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
|
||||||
|
{
|
||||||
|
int ks;
|
||||||
|
|
||||||
|
*ctl = CTL_NONE;
|
||||||
|
*chr = '\0';
|
||||||
|
|
||||||
|
ks = XKeycodeToKeysym(X_Dpy, kc, (state & ShiftMask) ? 1 : 0);
|
||||||
|
|
||||||
|
/* Look for control characters. */
|
||||||
|
switch (ks) {
|
||||||
|
case XK_BackSpace:
|
||||||
|
*ctl = CTL_ERASEONE;
|
||||||
|
break;
|
||||||
|
case XK_Return:
|
||||||
|
*ctl = CTL_RETURN;
|
||||||
|
break;
|
||||||
|
case XK_Up:
|
||||||
|
*ctl = CTL_UP;
|
||||||
|
break;
|
||||||
|
case XK_Down:
|
||||||
|
*ctl = CTL_DOWN;
|
||||||
|
break;
|
||||||
|
case XK_Escape:
|
||||||
|
*ctl = CTL_ABORT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ctl == CTL_NONE && (state & ControlMask)) {
|
||||||
|
switch (ks) {
|
||||||
|
case XK_s:
|
||||||
|
case XK_S:
|
||||||
|
/* Emacs "next" */
|
||||||
|
*ctl = CTL_DOWN;
|
||||||
|
break;
|
||||||
|
case XK_r:
|
||||||
|
case XK_R:
|
||||||
|
/* Emacs "previous" */
|
||||||
|
*ctl = CTL_UP;
|
||||||
|
break;
|
||||||
|
case XK_u:
|
||||||
|
case XK_U:
|
||||||
|
*ctl = CTL_WIPE;
|
||||||
|
break;
|
||||||
|
case XK_h:
|
||||||
|
case XK_H:
|
||||||
|
*ctl = CTL_ERASEONE;
|
||||||
|
break;
|
||||||
|
case XK_a:
|
||||||
|
case XK_A:
|
||||||
|
*ctl = CTL_ALL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ctl == CTL_NONE && (state & Mod1Mask)) {
|
||||||
|
switch (ks) {
|
||||||
|
case XK_j:
|
||||||
|
case XK_J:
|
||||||
|
/* Vi "down" */
|
||||||
|
*ctl = CTL_DOWN;
|
||||||
|
break;
|
||||||
|
case XK_k:
|
||||||
|
case XK_K:
|
||||||
|
/* Vi "up" */
|
||||||
|
*ctl = CTL_UP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ctl != CTL_NONE)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For regular characters, only (part of, actually) Latin 1
|
||||||
|
* for now.
|
||||||
|
*/
|
||||||
|
if (ks < 0x20 || ks > 0x07e)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
*chr = (char)ks;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user