support multibyte input to menu code; from Alexander Polakov with a tiny tweak.
This commit is contained in:
parent
484812f429
commit
f4e0469f06
@ -15,7 +15,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* $OpenBSD: calmwm.c,v 1.64 2012/07/18 21:53:22 okan Exp $
|
* $OpenBSD: calmwm.c,v 1.65 2012/08/07 14:05:49 okan Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -62,6 +63,10 @@ main(int argc, char **argv)
|
|||||||
char *display_name = NULL;
|
char *display_name = NULL;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
|
warnx("no locale support");
|
||||||
|
mbtowc(NULL, NULL, MB_CUR_MAX);
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "c:d:")) != -1) {
|
while ((ch = getopt(argc, argv, "c:d:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* $OpenBSD: menu.c,v 1.35 2012/07/13 15:21:35 okan Exp $
|
* $OpenBSD: menu.c,v 1.36 2012/08/07 14:05:49 okan Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -68,7 +68,7 @@ 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 *,
|
static int menu_keycode(XKeyEvent *, enum ctltype *,
|
||||||
char *);
|
char *);
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -208,16 +208,22 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
|||||||
{
|
{
|
||||||
struct menu *mi;
|
struct menu *mi;
|
||||||
enum ctltype ctl;
|
enum ctltype ctl;
|
||||||
char chr;
|
char chr[32];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
int clen, i;
|
||||||
|
wchar_t wc;
|
||||||
|
|
||||||
if (menu_keycode(e->xkey.keycode, e->xkey.state, &ctl, &chr) < 0)
|
if (menu_keycode(&e->xkey, &ctl, chr) < 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
switch (ctl) {
|
switch (ctl) {
|
||||||
case CTL_ERASEONE:
|
case CTL_ERASEONE:
|
||||||
if ((len = strlen(mc->searchstr)) > 0) {
|
if ((len = strlen(mc->searchstr)) > 0) {
|
||||||
mc->searchstr[len - 1] = '\0';
|
clen = 1;
|
||||||
|
while (mbtowc(&wc, &mc->searchstr[len-clen], MB_CUR_MAX) == -1)
|
||||||
|
clen++;
|
||||||
|
for (i = 1; i <= clen; i++)
|
||||||
|
mc->searchstr[len - i] = '\0';
|
||||||
mc->changed = 1;
|
mc->changed = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -267,13 +273,9 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chr != '\0') {
|
if (chr[0] != '\0') {
|
||||||
char str[2];
|
|
||||||
|
|
||||||
str[0] = chr;
|
|
||||||
str[1] = '\0';
|
|
||||||
mc->changed = 1;
|
mc->changed = 1;
|
||||||
(void)strlcat(mc->searchstr, str, sizeof(mc->searchstr));
|
(void)strlcat(mc->searchstr, chr, sizeof(mc->searchstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
mc->noresult = 0;
|
mc->noresult = 0;
|
||||||
@ -459,14 +461,16 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
|
menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr)
|
||||||
{
|
{
|
||||||
int ks;
|
KeySym ks;
|
||||||
|
u_int state = ev->state;
|
||||||
|
|
||||||
*ctl = CTL_NONE;
|
*ctl = CTL_NONE;
|
||||||
*chr = '\0';
|
chr[0] = '\0';
|
||||||
|
|
||||||
ks = XkbKeycodeToKeysym(X_Dpy, kc, 0, (state & ShiftMask) ? 1 : 0);
|
ks = XkbKeycodeToKeysym(X_Dpy, ev->keycode, 0,
|
||||||
|
(state & ShiftMask) ? 1 : 0);
|
||||||
|
|
||||||
/* Look for control characters. */
|
/* Look for control characters. */
|
||||||
switch (ks) {
|
switch (ks) {
|
||||||
@ -532,14 +536,8 @@ menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
|
|||||||
if (*ctl != CTL_NONE)
|
if (*ctl != CTL_NONE)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/*
|
if (XLookupString(ev, chr, 32, &ks, NULL) < 0)
|
||||||
* For regular characters, only (part of, actually) Latin 1
|
|
||||||
* for now.
|
|
||||||
*/
|
|
||||||
if (ks < 0x20 || ks > 0x07e)
|
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
*chr = (char)ks;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user