Skip to content

Commit

Permalink
* README.ja, PROTOCOL, mlterm.1: Updated.
Browse files Browse the repository at this point in the history
* ui_main_config.c: --fk / format_keys option is added.
* ui_screen.c:
  - INSERT_CLIPBOARD shortcut key is checked.
  - "paste" OSC 5379 command accepts "clipboard" argument.
* ui_shortcut.[ch]: INSERT_CLIPBOARD shortcut is added.
* xlib/ui_window.c:
  ui_set_use_clipboard_selection(2) makes ui_window_{utf|xct}_selection_request()
  call XConvertSelection() with XA_CLIPBOARD instead of XA_PRIMARY.
  XA_CLIPBOARD is regarded in processing SelectionNotify or PropertyNotify.
* vt_parser.[ch]:
  - vt_set_format_other_keys() which works as "formatOtherKeys" of xterm
    is added.
  - Compatiblity of the behavior of xterm with modifyOtherKeys = 1 is
    improved.
  - 'ch' is added to arguments of vt_parser_write_modified_key().
  • Loading branch information
arakiken committed Jun 11, 2021
1 parent 96ea847 commit f863ca5
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 48 deletions.
24 changes: 24 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
2021-06-11 Araki Ken <arakiken@users.sf.net>

* README.ja, PROTOCOL, mlterm.1: Updated.

* ui_main_config.c: --fk / format_keys option is added.

* ui_screen.c:
- INSERT_CLIPBOARD shortcut key is checked.
- "paste" OSC 5379 command accepts "clipboard" argument.

* ui_shortcut.[ch]: INSERT_CLIPBOARD shortcut is added.

* xlib/ui_window.c:
ui_set_use_clipboard_selection(2) makes ui_window_{utf|xct}_selection_request()
call XConvertSelection() with XA_CLIPBOARD instead of XA_PRIMARY.
XA_CLIPBOARD is regarded in processing SelectionNotify or PropertyNotify.

* vt_parser.[ch]:
- vt_set_format_other_keys() which works as "formatOtherKeys" of xterm
is added.
- Compatiblity of the behavior of xterm with modifyOtherKeys = 1 is
improved.
- 'ch' is added to arguments of vt_parser_write_modified_key().

2021-05-15 Araki Ken <arakiken@users.sf.net>

* README.ja, etc/key: Updated.
Expand Down
24 changes: 14 additions & 10 deletions doc/en/PROTOCOL
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ version 20201108
hsplit_screen (<rows>|<percent>%) |
mlclient "<prefix options>" "<options>" |
mlclientx "<prefix options>" "<options>" | mlconfig | next_pty | next_screen |
open_pty | open_screen | paste (*) | prev_pty | prev_screen |
open_pty | open_screen | paste (clipboard) (*) | prev_pty | prev_screen |
scp "(local:|remote:)<src file name>" "(local:|remote:)<dst directory name>"
"(<encoding name>)" |
search_next <pattern> | search_prev <pattern> | select_pty <dev> |
Expand All @@ -42,10 +42,11 @@ version 20201108
click_interval | co_color | col_size_of_width_a | console_encoding |
console_sixel_colors | contrast | cursor_bg_color | cursor_fg_color |
emoji_path | encoding | exit_backscroll_by_pty | fade_ratio | fg_color |
fontsize | gamma | geometry | hide_underline | icon_path | input_method |
it_color | letter_space | line_space | local_echo_wait | locale | logging_msg |
logging_vt_seq | logsize | mod_meta_key | mod_meta_mode | not_use_unicode_font |
only_use_unicode_font | ot_features | ot_script | receive_string_via_ucs |
fontsize | format_other_keys | gamma | geometry | hide_underline | icon_path |
input_method | it_color | letter_space | line_space | local_echo_wait |
locale | logging_msg | logging_vt_seq | logsize | mod_meta_key |
mod_meta_mode | not_use_unicode_font | only_use_unicode_font |
ot_features | ot_script | receive_string_via_ucs |
regard_uri_as_word | rv_color | sb_bg_color | sb_fg_color | screen_width_ratio |
scrollbar_mode | scrollbar_view_name | send_file static_backscroll_mode |
tabsize | trim_trailing_newline_in_pasting | type_engine | ul_color |
Expand All @@ -62,9 +63,10 @@ version 20201108
borderless | box_drawing_font | brightness | click_interval | co_color |
col_size_of_width_a | cols | contrast | cursor_bg_color | cursor_fg_color |
depth | emoji_path | encoding | fade_ratio | fg_color | fontconfig | fontsize |
gamma | gui | hide_underline | icon_path | input_method | is_auto_encoding |
it_color | letter_space | line_space | local_echo_wait | locale |
logging_vt_seq | logsize | mod_meta_key | mod_meta_mode | not_use_unicode_font |
format_other_keys | gamma | gui | hide_underline | icon_path |
input_method | is_auto_encoding | it_color | letter_space | line_space |
local_echo_wait | locale | logging_vt_seq | logsize | mod_meta_key |
mod_meta_mode | not_use_unicode_font |
only_use_unicode_font | ot_features | ot_script | pty_list | pty_name | pwd |
receive_directory | receive_string_via_ucs | regard_uri_as_word | rows |
rv_color | sb_bg_color | sb_fg_color | screen_width_ratio | scrollbar_mode |
Expand All @@ -77,7 +79,7 @@ version 20201108
use_ot_layout | use_transbg | use_variable_column_width | use_vertical_cursor |
vertical_mode | vt_seq_format | wall_picture | word_separators

(*): Works as "proto:xxxx" shortcut in ~/.mlterm/key.
(*): Works as "proto:xxxx" shortcut in ~/.mlterm/key alone.

value = <values for each key>
challenge = <string in ~/.mlterm/challenge>
Expand Down Expand Up @@ -118,6 +120,7 @@ version 20201108
encoding = <encoding name> | auto
fade_ratio = <any ASCII decimal digit>
fg_color = <color name> | <color rgb>
format_other_keys = true | false
fontsize = <any ASCII decimal digit> | larger | smaller
gamma = <any ASCII decimal digit>
hide_underline = true | false | switch
Expand Down Expand Up @@ -205,7 +208,8 @@ version 20201108
like Control+F1="proto:mlclient -osc52".
o "selected_text(:encoding)" command returns selected text in which NL is
replaced to CR.
o "paste" command works like INSERT_SELECTION.
o "paste" command works like INSERT_SELECTION, and "paste clipboard" command
works like INSERT_CLIPBOARD.
o "\x1b]5379;fontconfig\x07" shows current font settings.
o See doc/en/README.transfer for "scp" command.

Expand Down
5 changes: 5 additions & 0 deletions doc/en/ReleaseNote
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* Support GTK4 for mlconfig. (./configure --with-gtk=4.0)
* Add "MOSH_UDP_PORT" environmental variable to specify UDP port or port-range
to communicate with a mosh server.
* Add INSERT_CLIPBOARD shortcut key.
* Add --fk / format_other_keys option (equivalent to "formatOtherKeys" of xterm), and
change the default format of the escape sequence with modifyOtherKeys from
CSI Ps; Ps u to CSI 27; Ps; Ps ~.
* Add --with-iconv, --disable-daemon, --disable-split and --disable-zmodem
options to ./configure script.
* Add vte 0.64 API symbols to libvte compatible library.
Expand All @@ -24,6 +28,7 @@
Fix segfault if mlterm screen with -t option goes outside of the display.
Fix emoji glyphs becoming too large with cairo.
Fix corrupt value of "word_separator" option which mlconfig outputs.
Fix incompatibility with xterm in pressing Shift + a-z keys etc if modifyOtherKeys is 1.

ver 3.9.1
* Support copy mode which starts by Control+Shift+Return.
Expand Down
7 changes: 7 additions & 0 deletions doc/ja/README.ja
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ comment -*- mode: text; tab-width:2; indent-tabs-mode:nil -*-
o fb_resolution (mlterm-fb on NetBSD/x68k or OpenBSD ��)
768x512x4 �Τ褦�ʷ����Dz����٤����

o format_other_keys (true/*false*)
modifyOtherKeys ��ͭ���ʾ��������륨�������ץ������󥹤η�����
CSI 27; Ps; Ps ~ �ǤϤʤ� CSI Ps; Ps u �ˤ��롣
(xterm �� formatOtherKeys ��Ʊ��)

o geometry
ɽ�����֤����

Expand Down Expand Up @@ -1371,6 +1376,8 @@ comment -*- mode: text; tab-width:2; indent-tabs-mode:nil -*-
���ߤιԤ˥ޡ���
o INSERT_SELECTION(Shift+Insert)
���쥯�����Υڡ�����
o INSERT_CLIPBOARD(UNUSED) (xlib ��)
����åץܡ��ɤΥڡ�����
o RESET(Pause)
ü����ꥻ�å�
o COPY_MODE(Control+Shift+Return)
Expand Down
15 changes: 14 additions & 1 deletion man/mlterm.1
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ The default is \fB%.4x.png,%.4x-%.4x.png\fR.
Whether to exit backscroll mode on receiving data from pty.
The default is \fBfalse\fR.
.TP
\fB\-\-fk\fR(=\fIbool\fR)
Whether to send modified keys as parameter for CSI u.
(Equivalent to "formatOtherKeys" of xterm)
The default is \fBfalse\fR.
.TP
\fB\-\-fullwidth\fR=\fIvalue\fR
Force full width regardless of EastAsianWidth.txt.

Expand Down Expand Up @@ -1260,7 +1265,7 @@ Scroll down one page.
.TP
keys defined in \fBkey\fR configuration file
Shortcut keys work the same way as in normal mode.
(\fBINSERT_SELECTION\fR, \fBRESET\fR and \fBCOPY_MODE\fR
(\fBINSERT_SELECTION\fR, \fBINSERT_CLIPBOARD\fR, \fBRESET\fR and \fBCOPY_MODE\fR
exit from the backscroll mode.)
.TP

Expand Down Expand Up @@ -1592,6 +1597,10 @@ Specify encoding.
\fBexit_backscroll_by_pty=\fIbool\fR (\fB\-\-exitbs\fR)
Exit backscroll mode on receiving data from pty.
.TP
\fBformat_other_keys=\fIbool\fR (\fB\-\-fk\fR)
Send modified keys as parameter for CSI u.
(Equivalent to "formatOtherKeys" of xterm)
.TP
\fBfade_ratio=\fIratio\fR (\fB\-r\fR, \fB\-\-fade_ratio\fR)
Specify fading ratio when window is unfocused.
.TP
Expand Down Expand Up @@ -2045,6 +2054,7 @@ You can specify Button1, Button2, Button3, Button4 or Button5 as \fIKEY\fR.
\fBSCROLL_DOWN_TO_MARK\fR,
\fBSET_MARK\fR,
\fBINSERT_SELECTION\fR,
\fBINSERT_CLIPBOARD\fR,
\fBRESET\fR,
\fBCOPY_MODE\fR,
\fB"\fISTRING\fB"\fR,
Expand Down Expand Up @@ -2119,6 +2129,9 @@ Set mark to the current line (default \fBControl+Shift+m\fR).
\fBINSERT_SELECTION\fR
Insert selection (default \fBShift+Insert\fR).
.TP
\fBINSERT_CLIPBOARD\fR
Insert clipboard (default \fBUNUSED\fR). (Available on x11 alone)
.TP
\fBRESET\fR
Reset terminal (default \fBPause\fR).
.TP
Expand Down
10 changes: 10 additions & 0 deletions uitoolkit/ui_main_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ void ui_prepare_for_main_config(bl_conf_t *conf) {
"screen display at resize [wrap]");
bl_conf_add_opt(conf, '\0', "recvdir", 0, "receive_directory",
"directory to save received files [~/.mlterm/recv]");
bl_conf_add_opt(conf, '\0', "fk", 1, "format_other_keys",
"send modified keys as parameter for CSI u [false]");
#ifdef USE_IM_CURSOR_COLOR
bl_conf_add_opt(conf, '\0', "imcolor", 0, "im_cursor_color",
"cursor color when input method is activated. [false]");
Expand Down Expand Up @@ -1414,6 +1416,14 @@ void ui_main_config_init(ui_main_config_t *main_config, bl_conf_t *conf, int arg
vt_set_resize_mode(vt_get_resize_mode_by_name(value));
}

if ((value = bl_conf_get_value(conf, "format_other_keys"))) {
int flag = true_or_false(value);

if (flag != -1) {
vt_set_format_other_keys(flag);
}
}

if ((value = bl_conf_get_value(conf, "receive_directory"))) {
vt_set_recv_dir(value);
}
Expand Down
16 changes: 15 additions & 1 deletion uitoolkit/ui_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,12 @@ static int shortcut_match(ui_screen_t *screen, KeySym ksym, u_int state) {

if (ui_shortcut_match(screen->shortcut, INSERT_SELECTION, ksym, state)) {
yank_event_received(screen, CurrentTime);
} else if (ui_shortcut_match(screen->shortcut, INSERT_CLIPBOARD, ksym, state)) {
int flag = ui_is_using_clipboard_selection();

ui_set_use_clipboard_selection(2);
yank_event_received(screen, CurrentTime);
ui_set_use_clipboard_selection(flag);
} else if (ui_shortcut_match(screen->shortcut, RESET, ksym, state)) {
vt_term_reset(screen->term, 1);
} else if (ui_shortcut_match(screen->shortcut, COPY_MODE, ksym, state)) {
Expand Down Expand Up @@ -2604,7 +2610,7 @@ static void key_pressed(ui_window_t *win, XKeyEvent *event) {
* 0x80 on win32, framebuffer and wayland.
*/
(size == 1 && (key = kstr[0]) < 0x20)) {
if (vt_term_write_modified_key(screen->term, key, modcode)) {
if (vt_term_write_modified_key(screen->term, key, kstr[0], modcode)) {
return;
}
}
Expand Down Expand Up @@ -7026,7 +7032,15 @@ int ui_screen_exec_cmd(ui_screen_t *screen, char *cmd) {
* processing_vtseq == 0 : stop processing vtseq.
*/
if (screen->processing_vtseq <= 0) {
int flag = ui_is_using_clipboard_selection();

if (arg && strncmp(arg, "clip", 4) == 0) {
ui_set_use_clipboard_selection(2);
}

yank_event_received(screen, CurrentTime);

ui_set_use_clipboard_selection(flag);
}
} else if (strcmp(cmd, "open_pty") == 0 || strcmp(cmd, "select_pty") == 0) {
if (HAS_SYSTEM_LISTENER(screen, open_pty)) {
Expand Down
8 changes: 8 additions & 0 deletions uitoolkit/ui_shortcut.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ static key_func_table_t key_func_table[] = {
{ "SCROLL_UP_TO_MARK", SCROLL_UP_TO_MARK, },
{ "SCROLL_DOWN_TO_MARK", SCROLL_DOWN_TO_MARK, },
{ "INSERT_SELECTION", INSERT_SELECTION, },
#ifdef USE_XLIB
{ "INSERT_CLIPBOARD", INSERT_CLIPBOARD, },
#endif
{ "RESET", RESET, },
{ "COPY_MODE", COPY_MODE, },
{ "SET_MARK", SET_MARK, },
Expand Down Expand Up @@ -173,6 +176,11 @@ void ui_shortcut_init(ui_shortcut_t *shortcut) {
{ XK_Insert, ShiftMask, 1, },
#endif

#ifdef USE_XLIB
/* INSERT_CLIPBOARD */
{ 0, 0, 0, },
#endif

/* RESET */
{ XK_Pause, 0, 1, },

Expand Down
3 changes: 3 additions & 0 deletions uitoolkit/ui_shortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ typedef enum ui_key_func {
SCROLL_UP_TO_MARK,
SCROLL_DOWN_TO_MARK,
INSERT_SELECTION,
#ifdef USE_XLIB
INSERT_CLIPBOARD,
#endif
RESET,
COPY_MODE,
SET_MARK,
Expand Down
57 changes: 39 additions & 18 deletions uitoolkit/xlib/ui_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define XA_UTF8_STRING(display) (XInternAtom(display, "UTF8_STRING", False))
#define XA_BMP(display) (XInternAtom(display, "image/bmp", False))
#define XA_NONE(display) (XInternAtom(display, "NONE", False))
#define XA_SELECTION(display) (XInternAtom(display, "MLTERM_SELECTION", False))
#define XA_SELECTION_PROP(display) (XInternAtom(display, "MLTERM_SELECTION", False))
#define XA_DELETE_WINDOW(display) (XInternAtom(display, "WM_DELETE_WINDOW", False))
#define XA_TAKE_FOCUS(display) (XInternAtom(display, "WM_TAKE_FOCUS", False))
#define XA_INCR(display) (XInternAtom(display, "INCR", False))
Expand Down Expand Up @@ -2391,40 +2391,49 @@ int ui_window_receive_event(ui_window_t *win, XEvent *event) {
Atom xa_utf8_string;
Atom xa_compound_text;
Atom xa_text;
Atom xa_selection;
Atom xa_selection_property;

xa_compound_text = XA_COMPOUND_TEXT(win->disp->display);
xa_text = XA_TEXT(win->disp->display);
xa_utf8_string = XA_UTF8_STRING(win->disp->display);
xa_selection = XA_SELECTION(win->disp->display);
xa_selection_property = XA_SELECTION_PROP(win->disp->display);

if (event->xselection.property == None ||
event->xselection.property == XA_NONE(win->disp->display)) {
Atom xa_selection;

if (use_clipboard == 2) {
xa_selection = XA_CLIPBOARD(win->disp->display);
} else {
xa_selection = XA_PRIMARY;
}

/*
* Selection request failed.
* Retrying with xa_compound_text => xa_text => XA_STRING
*/

if (event->xselection.target == xa_utf8_string) {
XConvertSelection(win->disp->display, XA_PRIMARY, xa_compound_text, xa_selection,
XConvertSelection(win->disp->display, xa_selection, xa_compound_text, xa_selection_property,
win->my_window, CurrentTime);
} else if (event->xselection.target == xa_compound_text) {
XConvertSelection(win->disp->display, XA_PRIMARY, xa_text, xa_selection, win->my_window,
CurrentTime);
XConvertSelection(win->disp->display, xa_selection, xa_text, xa_selection_property,
win->my_window, CurrentTime);
} else if (event->xselection.target == xa_text) {
XConvertSelection(win->disp->display, XA_PRIMARY, XA_STRING, xa_selection, win->my_window,
CurrentTime);
XConvertSelection(win->disp->display, xa_selection, XA_STRING, xa_selection_property,
win->my_window, CurrentTime);
}

return 1;
}

/* SELECTION */
if (event->xselection.selection == XA_PRIMARY &&
(event->xselection.property == xa_selection &&
(event->xselection.target == XA_STRING || event->xselection.target == xa_text ||
event->xselection.target == xa_compound_text ||
event->xselection.target == xa_utf8_string))) {
if ((event->xselection.selection == XA_PRIMARY ||
event->xselection.selection == XA_CLIPBOARD(win->disp->display)) &&
event->xselection.property == xa_selection_property &&
(event->xselection.target == XA_STRING || event->xselection.target == xa_text ||
event->xselection.target == xa_compound_text ||
event->xselection.target == xa_utf8_string)) {
u_long bytes_after;
XTextProperty ct;
int seg;
Expand Down Expand Up @@ -2484,7 +2493,7 @@ int ui_window_receive_event(ui_window_t *win, XEvent *event) {
}
#endif
} else if (event->type == PropertyNotify) {
if (event->xproperty.atom == XA_SELECTION(win->disp->display) &&
if (event->xproperty.atom == XA_SELECTION_PROP(win->disp->display) &&
event->xproperty.state == PropertyNewValue) {
XTextProperty ct;
u_long bytes_after;
Expand Down Expand Up @@ -2948,15 +2957,27 @@ int ui_window_set_selection_owner(ui_window_t *win, Time time) {
}

int ui_window_xct_selection_request(ui_window_t *win, Time time) {
XConvertSelection(win->disp->display, XA_PRIMARY, XA_COMPOUND_TEXT(win->disp->display),
XA_SELECTION(win->disp->display), win->my_window, time);
Display *display = win->disp->display;

/*
* XXX
* XA_COMPOUND_TEXT doesn't work with Cygwin/X11 server 1.20.9.0.
* XGetWindowProperty() returns the following 86 bytes.
* -> e4bd83e5818de5958fe4918ee5919fe5a185e28194e6bdaee281b4e6b5a9e6b1b0
* e6b5a5e6b9a5e695b464e69593e695ace791a3e6bda9e589aee785a5e695b5e791
* b3e2b4a0e790a0e789a1e695a7e281b4e690a50a
*/
XConvertSelection(display, use_clipboard == 2 ? XA_CLIPBOARD(display) : XA_PRIMARY,
XA_COMPOUND_TEXT(display), XA_SELECTION_PROP(display), win->my_window, time);

return 1;
}

int ui_window_utf_selection_request(ui_window_t *win, Time time) {
XConvertSelection(win->disp->display, XA_PRIMARY, XA_UTF8_STRING(win->disp->display),
XA_SELECTION(win->disp->display), win->my_window, time);
Display *display = win->disp->display;

XConvertSelection(display, use_clipboard == 2 ? XA_CLIPBOARD(display) : XA_PRIMARY,
XA_UTF8_STRING(display), XA_SELECTION_PROP(display), win->my_window, time);

return 1;
}
Expand Down
Loading

0 comments on commit f863ca5

Please sign in to comment.