Skip to content

Commit

Permalink
* xlib/ui_window.c: ui_set_use_clipboard_selection() calls
Browse files Browse the repository at this point in the history
  ui_display_clear_selection() only if use_clipboard == 0 and use_it == 1.
* wayland/ui_display.c:
  - ui_set_use_clipboard_selection() and ui_is_using_clipboard_selection()
    are added.
  - If disp_name is "", ui_display_open() uses WAYLAND_DISPLAY environmental
    variable.
* ui_screen.c, ui_shortcut.[ch]: INSERT_CLIPBOARD is available on wayland.
* ui_main_config.c: The default value of "display" option is changed
  from "wayland-0" to "" on wayland.
* MLActivity.java: servListDialogLayout and connectDialogLayout
  are set to null after finishing dialogs.
  • Loading branch information
arakiken committed Jul 24, 2021
1 parent d02822d commit c87f20d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 19 deletions.
19 changes: 19 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2021-07-24 Araki Ken <arakiken@users.sf.net>

* xlib/ui_window.c: ui_set_use_clipboard_selection() calls
ui_display_clear_selection() only if use_clipboard == 0 and use_it == 1.

* wayland/ui_display.c:
- ui_set_use_clipboard_selection() and ui_is_using_clipboard_selection()
are added.
- If disp_name is "", ui_display_open() uses WAYLAND_DISPLAY environmental
variable.

* ui_screen.c, ui_shortcut.[ch]: INSERT_CLIPBOARD is available on wayland.

* ui_main_config.c: The default value of "display" option is changed
from "wayland-0" to "" on wayland.

* MLActivity.java: servListDialogLayout and connectDialogLayout
are set to null after finishing dialogs.

2021-07-10 Araki Ken <arakiken@users.sf.net>

* sdl2/ui.h: ALPHA_TO_PIXEL macro is defined.
Expand Down
2 changes: 2 additions & 0 deletions android/src/mlterm/native_activity/MLActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ private void showServerList() {
}

removeDialog(1);
servListDialogLayout = null;
}

/* Called from native activity thread */
Expand Down Expand Up @@ -1000,6 +1001,7 @@ private void showConnectDialog(String proto, String user, String serv, String po
removeDialog(1);

serv_edit = port_edit = user_edit = pass_edit = encoding_edit = cmd_edit = privkey_edit = null;
connectDialogLayout = null;
}

/* Called from native activity thread or UI thread (from context menu) */
Expand Down
3 changes: 3 additions & 0 deletions uitoolkit/fb/ui_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -2372,9 +2372,12 @@ void ui_window_draw_rect_frame(ui_window_t *win, int x1, int y1, int x2, int y2)
ui_window_fill_with(win, &win->fg_color, x2, y1, 1, y2 - y1 + 1);
}

/* These functions are defined in ui_display.c on wayland. */
#ifndef USE_WAYLAND
void ui_set_use_clipboard_selection(int use_it) {}

int ui_is_using_clipboard_selection(void) { return 0; }
#endif

int ui_window_set_selection_owner(ui_window_t *win, Time time) {
#ifndef USE_SDL2
Expand Down
8 changes: 4 additions & 4 deletions uitoolkit/ui_main_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@

/* --- static variables --- */

#ifdef USE_WAYLAND
static char *default_display = "wayland-0";
#else
static char *default_display = "";
#endif

/* --- static functions --- */

Expand Down Expand Up @@ -362,6 +358,10 @@ void ui_main_config_init(ui_main_config_t *main_config, bl_conf_t *conf, int arg
!(main_config->disp_name = strdup(value)))
#endif
{
/*
* default_display ("") is replaced by getenv("WAYLAND_DISPLAY") on wayland.
* (See ui_display_open() in wayland/ui_display.c)
*/
main_config->disp_name = default_display;
#ifdef USE_XLIB
/* In case of starting mlterm with "-j genuine" option without X server. */
Expand Down
4 changes: 2 additions & 2 deletions uitoolkit/ui_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2001,13 +2001,13 @@ 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);
}
#ifdef USE_XLIB
#if defined(USE_XLIB) || defined(USE_WAYLAND)
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);
ui_set_use_clipboard_selection(flag);
}
#endif
else if (ui_shortcut_match(screen->shortcut, RESET, ksym, state)) {
Expand Down
4 changes: 2 additions & 2 deletions uitoolkit/ui_shortcut.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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
#if defined(USE_XLIB) || defined(USE_WAYLAND)
{ "INSERT_CLIPBOARD", INSERT_CLIPBOARD, },
#endif
{ "RESET", RESET, },
Expand Down Expand Up @@ -176,7 +176,7 @@ void ui_shortcut_init(ui_shortcut_t *shortcut) {
{ XK_Insert, ShiftMask, 1, },
#endif

#ifdef USE_XLIB
#if defined(USE_XLIB) || defined(USE_WAYLAND)
/* INSERT_CLIPBOARD */
{ 0, 0, 0, },
#endif
Expand Down
2 changes: 1 addition & 1 deletion uitoolkit/ui_shortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef enum ui_key_func {
SCROLL_UP_TO_MARK,
SCROLL_DOWN_TO_MARK,
INSERT_SELECTION,
#ifdef USE_XLIB
#if defined(USE_XLIB) || defined(USE_WAYLAND)
INSERT_CLIPBOARD,
#endif
RESET,
Expand Down
42 changes: 40 additions & 2 deletions uitoolkit/wayland/ui_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static ui_wlserv_t **wlservs;
static u_int num_displays;
static ui_display_t **displays;
static int rotate_display;
static int use_clipboard = 1;
int kbd_repeat_1 = DEFAULT_KEY_REPEAT_1;
int kbd_repeat_N = DEFAULT_KEY_REPEAT_N;

Expand Down Expand Up @@ -2488,6 +2489,12 @@ ui_display_t *ui_display_open(char *disp_name, u_int depth) {
displays = p;
displays[num_displays] = disp;

if (*disp_name == '\0') {
if ((disp_name = getenv("WAYLAND_DISPLAY")) == NULL) {
disp_name = "wayland-0";
}
}

for (count = 0; count < num_displays; count++) {
if (strcmp(displays[count]->name, disp_name) == 0) {
disp->selection_owner = displays[count]->selection_owner;
Expand Down Expand Up @@ -2815,6 +2822,37 @@ void ui_display_sync(ui_display_t *disp) {
#endif
}

void ui_set_use_clipboard_selection(int use_it) {
u_int count;

/* "use_clipboard = false" setting is disabled on wayland. */
if (use_it == 0) {
bl_msg_printf("use_clipboard=false is ignored on wayland.\n");

return;
} else if (use_clipboard == use_it) {
return;
}

if (use_clipboard == 0 && use_it == 1) {
/*
* disp->selection_owner is reset.
* If it isn't reset and value of 'use_clipboard' option is changed from false
* to true dynamically, ui_window_set_selection_owner() returns before calling
* wl_data_device_manager_create_data_source().
*/
for (count = 0; count < num_displays; count++) {
if (displays[count]->selection_owner) {
ui_display_clear_selection(NULL, displays[count]->selection_owner);
}
}
}

use_clipboard = use_it;
}

int ui_is_using_clipboard_selection(void) { return use_clipboard; }

/*
* Folloing functions called from ui_window.c
*/
Expand Down Expand Up @@ -2848,7 +2886,7 @@ int ui_display_own_selection(ui_display_t *disp, ui_window_t *win) {
wlserv->xsel_source, wlserv->serial);
}

if (wlserv->data_device_manager) {
if (use_clipboard && wlserv->data_device_manager) {
wlserv->sel_source = wl_data_device_manager_create_data_source(wlserv->data_device_manager);
wl_data_source_offer(wlserv->sel_source, "UTF8_STRING");
/* wl_data_source_offer(wlserv->sel_source, "COMPOUND_TEXT"); */
Expand Down Expand Up @@ -3152,7 +3190,7 @@ void ui_display_request_text_selection(ui_display_t *disp) {
} else {
ui_wlserv_t *wlserv = disp->display->wlserv;

if (wlserv->xsel_offer && wlserv->xsel_offer_mime) {
if (use_clipboard != 2 && wlserv->xsel_offer && wlserv->xsel_offer_mime) {
receive_data(disp, wlserv->xsel_offer, wlserv->xsel_offer_mime, 0);
} else if (wlserv->sel_offer && wlserv->sel_offer_mime) {
receive_data(disp, wlserv->sel_offer, wlserv->sel_offer_mime, 1);
Expand Down
18 changes: 10 additions & 8 deletions uitoolkit/xlib/ui_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -2914,15 +2914,17 @@ void ui_set_use_clipboard_selection(int use_it) {
return;
}

use_clipboard = use_it;
if (use_clipboard == 0 && use_it == 1) {
/*
* disp->selection_owner is reset.
* If it isn't reset and value of 'use_clipboard' option is changed from false
* to true dynamically, ui_window_set_selection_owner() returns before calling
* XSetSelectionOwner().
*/
ui_display_clear_selection(NULL, NULL);
}

/*
* disp->selection_owner is reset.
* If it isn't reset and value of 'use_clipboard' option is changed from false
* to true dynamically, ui_window_set_selection_owner() returns before calling
* XSetSelectionOwner().
*/
ui_display_clear_selection(NULL, NULL);
use_clipboard = use_it;
}

int ui_is_using_clipboard_selection(void) { return use_clipboard; }
Expand Down

0 comments on commit c87f20d

Please sign in to comment.