mirror of
https://github.com/mintycube/st.git
synced 2024-10-22 14:05:49 +02:00
keyboardselect: style changes
This commit is contained in:
parent
d7b6b1c1c6
commit
6c42872476
@ -1,222 +1,222 @@
|
|||||||
void set_notifmode(int type, KeySym ksym) {
|
void set_notifmode(int type, KeySym ksym)
|
||||||
static char *lib[] = { " MOVE ", " SEL "};
|
{
|
||||||
static Glyph *g, *deb, *fin;
|
static char *lib[] = { " MOVE ", " SEL "};
|
||||||
static int col, bot;
|
static Glyph *g, *deb, *fin;
|
||||||
|
static int col, bot;
|
||||||
|
|
||||||
if ( ksym == -1 ) {
|
if (ksym == -1) {
|
||||||
free(g);
|
free(g);
|
||||||
col = term.col, bot = term.bot;
|
col = term.col, bot = term.bot;
|
||||||
g = xmalloc(col * sizeof(Glyph));
|
g = xmalloc(col * sizeof(Glyph));
|
||||||
memcpy(g, term.line[bot], col * sizeof(Glyph));
|
memcpy(g, term.line[bot], col * sizeof(Glyph));
|
||||||
|
|
||||||
}
|
} else if (ksym == -2)
|
||||||
else if ( ksym == -2 )
|
memcpy(term.line[bot], g, col * sizeof(Glyph));
|
||||||
memcpy(term.line[bot], g, col * sizeof(Glyph));
|
|
||||||
|
|
||||||
if ( type < 2 ) {
|
if ( type < 2 ) {
|
||||||
char *z = lib[type];
|
char *z = lib[type];
|
||||||
for (deb = &term.line[bot][col - 6], fin = &term.line[bot][col]; deb < fin; z++, deb++)
|
for (deb = &term.line[bot][col - 6], fin = &term.line[bot][col]; deb < fin; z++, deb++)
|
||||||
deb->mode = ATTR_REVERSE,
|
deb->mode = ATTR_REVERSE,
|
||||||
deb->u = *z,
|
deb->u = *z,
|
||||||
deb->fg = defaultfg, deb->bg = defaultbg;
|
deb->fg = defaultfg, deb->bg = defaultbg;
|
||||||
}
|
} else if (type < 5)
|
||||||
else if ( type < 5 )
|
memcpy(term.line[bot], g, col * sizeof(Glyph));
|
||||||
memcpy(term.line[bot], g, col * sizeof(Glyph));
|
else {
|
||||||
else {
|
for (deb = &term.line[bot][0], fin = &term.line[bot][col]; deb < fin; deb++)
|
||||||
for (deb = &term.line[bot][0], fin = &term.line[bot][col]; deb < fin; deb++)
|
deb->mode = ATTR_REVERSE,
|
||||||
deb->mode = ATTR_REVERSE,
|
deb->u = ' ',
|
||||||
deb->u = ' ',
|
deb->fg = defaultfg, deb->bg = defaultbg;
|
||||||
deb->fg = defaultfg, deb->bg = defaultbg;
|
term.line[bot][0].u = ksym;
|
||||||
term.line[bot][0].u = ksym;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
term.dirty[bot] = 1;
|
term.dirty[bot] = 1;
|
||||||
drawregion(0, bot, col, bot + 1);
|
drawregion(0, bot, col, bot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_or_drawcursor(int selectsearch_mode, int type) {
|
void select_or_drawcursor(int selectsearch_mode, int type)
|
||||||
int done = 0;
|
{
|
||||||
|
int done = 0;
|
||||||
|
|
||||||
if ( selectsearch_mode & 1 ) {
|
if (selectsearch_mode & 1) {
|
||||||
selextend(term.c.x, term.c.y, type, done);
|
selextend(term.c.x, term.c.y, type, done);
|
||||||
xsetsel(getsel());
|
xsetsel(getsel());
|
||||||
}
|
} else {
|
||||||
else
|
#if LIGATURES_PATCH
|
||||||
#if LIGATURES_PATCH
|
xdrawcursor(term.c.x, term.c.y, term.line[term.c.y][term.c.x],
|
||||||
xdrawcursor(term.c.x, term.c.y, term.line[term.c.y][term.c.x],
|
term.ocx, term.ocy, term.line[term.ocy][term.ocx],
|
||||||
term.ocx, term.ocy, term.line[term.ocy][term.ocx],
|
term.line[term.ocy], term.col);
|
||||||
term.line[term.ocy], term.col);
|
#else
|
||||||
#else
|
xdrawcursor(term.c.x, term.c.y, term.line[term.c.y][term.c.x],
|
||||||
xdrawcursor(term.c.x, term.c.y, term.line[term.c.y][term.c.x],
|
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
||||||
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
#endif // LIGATURES_PATCH
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void search(int selectsearch_mode, Rune *target, int ptarget, int incr, int type, TCursor *cu) {
|
void search(int selectsearch_mode, Rune *target, int ptarget, int incr, int type, TCursor *cu)
|
||||||
Rune *r;
|
{
|
||||||
int i, bound = (term.col * cu->y + cu->x) * (incr > 0) + incr;
|
Rune *r;
|
||||||
|
int i, bound = (term.col * cu->y + cu->x) * (incr > 0) + incr;
|
||||||
|
|
||||||
for (i = term.col * term.c.y + term.c.x + incr; i != bound; i += incr) {
|
for (i = term.col * term.c.y + term.c.x + incr; i != bound; i += incr) {
|
||||||
for (r = target; r - target < ptarget; r++) {
|
for (r = target; r - target < ptarget; r++) {
|
||||||
if ( *r == term.line[(i + r - target) / term.col][(i + r - target) % term.col].u ) {
|
if (*r == term.line[(i + r - target) / term.col][(i + r - target) % term.col].u) {
|
||||||
if ( r - target == ptarget - 1 ) break;
|
if (r - target == ptarget - 1)
|
||||||
} else {
|
break;
|
||||||
r = NULL;
|
} else {
|
||||||
break;
|
r = NULL;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if ( r != NULL ) break;
|
}
|
||||||
}
|
if (r != NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( i != bound ) {
|
if (i != bound) {
|
||||||
term.c.y = i / term.col, term.c.x = i % term.col;
|
term.c.y = i / term.col, term.c.x = i % term.col;
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int trt_kbdselect(KeySym ksym, char *buf, int len) {
|
int trt_kbdselect(KeySym ksym, char *buf, int len)
|
||||||
static TCursor cu;
|
{
|
||||||
static Rune target[64];
|
static TCursor cu;
|
||||||
static int type = 1, ptarget, in_use;
|
static Rune target[64];
|
||||||
static int sens, quant;
|
static int type = 1, ptarget, in_use;
|
||||||
static char selectsearch_mode;
|
static int sens, quant;
|
||||||
int i, bound, *xy;
|
static char selectsearch_mode;
|
||||||
|
int i, bound, *xy;
|
||||||
|
|
||||||
|
if (selectsearch_mode & 2) {
|
||||||
if ( selectsearch_mode & 2 ) {
|
if (ksym == XK_Return) {
|
||||||
if ( ksym == XK_Return ) {
|
|
||||||
selectsearch_mode ^= 2;
|
selectsearch_mode ^= 2;
|
||||||
set_notifmode(selectsearch_mode, -2);
|
set_notifmode(selectsearch_mode, -2);
|
||||||
if ( ksym == XK_Escape ) ptarget = 0;
|
if (ksym == XK_Escape)
|
||||||
|
ptarget = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (ksym == XK_BackSpace) {
|
||||||
else if ( ksym == XK_BackSpace ) {
|
if (!ptarget)
|
||||||
if ( !ptarget ) return 0;
|
return 0;
|
||||||
term.line[term.bot][ptarget--].u = ' ';
|
term.line[term.bot][ptarget--].u = ' ';
|
||||||
}
|
} else if (len < 1) {
|
||||||
else if ( len < 1 ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (ptarget == term.col || ksym == XK_Escape) {
|
||||||
else if ( ptarget == term.col || ksym == XK_Escape ) {
|
return 0;
|
||||||
return 0;
|
} else {
|
||||||
}
|
utf8decode(buf, &target[ptarget++], len);
|
||||||
else {
|
term.line[term.bot][ptarget].u = target[ptarget - 1];
|
||||||
utf8decode(buf, &target[ptarget++], len);
|
|
||||||
term.line[term.bot][ptarget].u = target[ptarget - 1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ksym != XK_BackSpace )
|
if (ksym != XK_BackSpace)
|
||||||
search(selectsearch_mode, &target[0], ptarget, sens, type, &cu);
|
search(selectsearch_mode, &target[0], ptarget, sens, type, &cu);
|
||||||
|
|
||||||
term.dirty[term.bot] = 1;
|
term.dirty[term.bot] = 1;
|
||||||
drawregion(0, term.bot, term.col, term.bot + 1);
|
drawregion(0, term.bot, term.col, term.bot + 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( ksym ) {
|
switch (ksym) {
|
||||||
case -1 :
|
case -1:
|
||||||
in_use = 1;
|
in_use = 1;
|
||||||
cu.x = term.c.x, cu.y = term.c.y;
|
cu.x = term.c.x, cu.y = term.c.y;
|
||||||
set_notifmode(0, ksym);
|
set_notifmode(0, ksym);
|
||||||
return MODE_KBDSELECT;
|
return MODE_KBDSELECT;
|
||||||
case XK_s :
|
case XK_s:
|
||||||
if ( selectsearch_mode & 1 )
|
if (selectsearch_mode & 1)
|
||||||
selclear();
|
selclear();
|
||||||
else
|
else
|
||||||
selstart(term.c.x, term.c.y, 0);
|
selstart(term.c.x, term.c.y, 0);
|
||||||
set_notifmode(selectsearch_mode ^= 1, ksym);
|
set_notifmode(selectsearch_mode ^= 1, ksym);
|
||||||
break;
|
break;
|
||||||
case XK_t :
|
case XK_t:
|
||||||
selextend(term.c.x, term.c.y, type ^= 3, i = 0); /* 2 fois */
|
selextend(term.c.x, term.c.y, type ^= 3, i = 0); /* 2 fois */
|
||||||
selextend(term.c.x, term.c.y, type, i = 0);
|
selextend(term.c.x, term.c.y, type, i = 0);
|
||||||
break;
|
break;
|
||||||
case XK_slash :
|
case XK_slash:
|
||||||
case XK_KP_Divide :
|
case XK_KP_Divide:
|
||||||
case XK_question :
|
case XK_question:
|
||||||
ksym &= XK_question; /* Divide to slash */
|
ksym &= XK_question; /* Divide to slash */
|
||||||
sens = (ksym == XK_slash) ? -1 : 1;
|
sens = (ksym == XK_slash) ? -1 : 1;
|
||||||
ptarget = 0;
|
ptarget = 0;
|
||||||
set_notifmode(15, ksym);
|
set_notifmode(15, ksym);
|
||||||
selectsearch_mode ^= 2;
|
selectsearch_mode ^= 2;
|
||||||
break;
|
break;
|
||||||
case XK_Escape :
|
case XK_Escape:
|
||||||
if ( !in_use ) break;
|
if (!in_use)
|
||||||
selclear();
|
break;
|
||||||
case XK_Return :
|
selclear();
|
||||||
set_notifmode(4, ksym);
|
case XK_Return:
|
||||||
term.c.x = cu.x, term.c.y = cu.y;
|
set_notifmode(4, ksym);
|
||||||
select_or_drawcursor(selectsearch_mode = 0, type);
|
term.c.x = cu.x, term.c.y = cu.y;
|
||||||
in_use = quant = 0;
|
select_or_drawcursor(selectsearch_mode = 0, type);
|
||||||
return MODE_KBDSELECT;
|
in_use = quant = 0;
|
||||||
case XK_n :
|
return MODE_KBDSELECT;
|
||||||
case XK_N :
|
case XK_n:
|
||||||
if ( ptarget )
|
case XK_N:
|
||||||
search(selectsearch_mode, &target[0], ptarget, (ksym == XK_n) ? -1 : 1, type, &cu);
|
if (ptarget)
|
||||||
break;
|
search(selectsearch_mode, &target[0], ptarget, (ksym == XK_n) ? -1 : 1, type, &cu);
|
||||||
case XK_BackSpace :
|
break;
|
||||||
term.c.x = 0;
|
case XK_BackSpace:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.x = 0;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
case XK_dollar :
|
break;
|
||||||
term.c.x = term.col - 1;
|
case XK_dollar:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.x = term.col - 1;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
case XK_Home :
|
break;
|
||||||
term.c.x = 0, term.c.y = 0;
|
case XK_Home:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.x = 0, term.c.y = 0;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
case XK_End :
|
break;
|
||||||
term.c.x = cu.x, term.c.y = cu.y;
|
case XK_End:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.x = cu.x, term.c.y = cu.y;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
case XK_Page_Up :
|
break;
|
||||||
case XK_Page_Down :
|
case XK_Page_Up:
|
||||||
term.c.y = (ksym == XK_Prior ) ? 0 : cu.y;
|
case XK_Page_Down:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.y = (ksym == XK_Prior ) ? 0 : cu.y;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
case XK_exclam :
|
break;
|
||||||
term.c.x = term.col >> 1;
|
case XK_exclam:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.x = term.col >> 1;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
case XK_asterisk :
|
break;
|
||||||
case XK_KP_Multiply :
|
case XK_asterisk:
|
||||||
term.c.x = term.col >> 1;
|
case XK_KP_Multiply:
|
||||||
case XK_underscore :
|
term.c.x = term.col >> 1;
|
||||||
term.c.y = cu.y >> 1;
|
case XK_underscore:
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
term.c.y = cu.y >> 1;
|
||||||
break;
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
default :
|
break;
|
||||||
if ( ksym >= XK_0 && ksym <= XK_9 ) { /* 0-9 keyboard */
|
default:
|
||||||
quant = (quant * 10) + (ksym ^ XK_0);
|
if (ksym >= XK_0 && ksym <= XK_9) { /* 0-9 keyboard */
|
||||||
return 0;
|
quant = (quant * 10) + (ksym ^ XK_0);
|
||||||
}
|
return 0;
|
||||||
else if ( ksym >= XK_KP_0 && ksym <= XK_KP_9 ) { /* 0-9 numpad */
|
} else if (ksym >= XK_KP_0 && ksym <= XK_KP_9) { /* 0-9 numpad */
|
||||||
quant = (quant * 10) + (ksym ^ XK_KP_0);
|
quant = (quant * 10) + (ksym ^ XK_KP_0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (ksym == XK_k || ksym == XK_h)
|
||||||
else if ( ksym == XK_k || ksym == XK_h )
|
i = ksym & 1;
|
||||||
i = ksym & 1;
|
else if (ksym == XK_l || ksym == XK_j)
|
||||||
else if ( ksym == XK_l || ksym == XK_j )
|
i = ((ksym & 6) | 4) >> 1;
|
||||||
i = ((ksym & 6) | 4) >> 1;
|
else if ((XK_Home & ksym) != XK_Home || (i = (ksym ^ XK_Home) - 1) > 3)
|
||||||
else if ( (XK_Home & ksym) != XK_Home || (i = (ksym ^ XK_Home) - 1) > 3 )
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
xy = (i & 1) ? &term.c.y : &term.c.x;
|
xy = (i & 1) ? &term.c.y : &term.c.x;
|
||||||
sens = (i & 2) ? 1 : -1;
|
sens = (i & 2) ? 1 : -1;
|
||||||
bound = (i >> 1 ^ 1) ? 0 : (i ^ 3) ? term.col - 1 : term.bot;
|
bound = (i >> 1 ^ 1) ? 0 : (i ^ 3) ? term.col - 1 : term.bot;
|
||||||
|
|
||||||
if ( quant == 0 )
|
if (quant == 0)
|
||||||
quant++;
|
quant++;
|
||||||
|
|
||||||
if ( *xy == bound && ((sens < 0 && bound == 0) || (sens > 0 && bound > 0)) )
|
if (*xy == bound && ((sens < 0 && bound == 0) || (sens > 0 && bound > 0)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
*xy += quant * sens;
|
*xy += quant * sens;
|
||||||
if ( *xy < 0 || ( bound > 0 && *xy > bound) )
|
if (*xy < 0 || ( bound > 0 && *xy > bound))
|
||||||
*xy = bound;
|
*xy = bound;
|
||||||
|
|
||||||
select_or_drawcursor(selectsearch_mode, type);
|
select_or_drawcursor(selectsearch_mode, type);
|
||||||
}
|
}
|
||||||
quant = 0;
|
quant = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user