From 4ecb0ecf4d1f45df918a8dd2dbabd6e9d7090dcc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 15:58:52 +0100 Subject: wayland: rename focused/moused to kbd_focus/mouse_focus --- terminal.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 64bdebe3..a9ed686f 100644 --- a/terminal.c +++ b/terminal.c @@ -716,13 +716,13 @@ fdm_shutdown(struct fdm *fdm, int fd, int events, void *data) * are deferred (for example, when a screen locker is active), and * thus we can get here without having been unmapped. */ - if (wayl->focused == term) - wayl->focused = NULL; - if (wayl->moused == term) - wayl->moused = NULL; + if (wayl->kbd_focus == term) + wayl->kbd_focus = NULL; + if (wayl->mouse_focus == term) + wayl->mouse_focus = NULL; - assert(wayl->focused != term); - assert(wayl->moused != term); + assert(wayl->kbd_focus != term); + assert(wayl->mouse_focus != term); void (*cb)(void *, int) = term->shutdown_cb; void *cb_data = term->shutdown_data; @@ -1234,7 +1234,7 @@ void term_cursor_blink_enable(struct terminal *term) { term->cursor_blink.state = CURSOR_BLINK_ON; - term->cursor_blink.active = term->wl->focused == term + term->cursor_blink.active = term->wl->kbd_focus == term ? cursor_blink_start_timer(term) : true; cursor_refresh(term); } @@ -1253,7 +1253,7 @@ term_cursor_blink_restart(struct terminal *term) { if (term->cursor_blink.active) { term->cursor_blink.state = CURSOR_BLINK_ON; - term->cursor_blink.active = term->wl->focused == term + term->cursor_blink.active = term->wl->kbd_focus == term ? cursor_blink_start_timer(term) : true; } } @@ -1508,7 +1508,7 @@ term_mouse_grabbed(const struct terminal *term) * Mouse is grabbed by us, regardless of whether mouse tracking has been enabled or not. */ return - term->wl->focused == term && + term->wl->kbd_focus == term && term->wl->kbd.shift && !term->wl->kbd.alt && !term->wl->kbd.ctrl && !term->wl->kbd.meta; } @@ -1529,7 +1529,7 @@ term_mouse_down(struct terminal *term, int button, int row, int col) return; - bool has_focus = term->wl->focused == term; + bool has_focus = term->wl->kbd_focus == term; bool shift = has_focus ? term->wl->kbd.shift : false; bool alt = has_focus ? term->wl->kbd.alt : false; bool ctrl = has_focus ? term->wl->kbd.ctrl : false; @@ -1573,7 +1573,7 @@ term_mouse_up(struct terminal *term, int button, int row, int col) if (encoded == -1) return; - bool has_focus = term->wl->focused == term; + bool has_focus = term->wl->kbd_focus == term; bool shift = has_focus ? term->wl->kbd.shift : false; bool alt = has_focus ? term->wl->kbd.alt : false; bool ctrl = has_focus ? term->wl->kbd.ctrl : false; @@ -1617,7 +1617,7 @@ term_mouse_motion(struct terminal *term, int button, int row, int col) } else encoded = 3; /* "released" */ - bool has_focus = term->wl->focused == term; + bool has_focus = term->wl->kbd_focus == term; bool shift = has_focus ? term->wl->kbd.shift : false; bool alt = has_focus ? term->wl->kbd.alt : false; bool ctrl = has_focus ? term->wl->kbd.ctrl : false; -- cgit v1.3 From e9325b958f6fb6416f77a1f0d9f8b049f6a6a46b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 19:29:42 +0100 Subject: term: rename term_focus_{in,out} -> term_kbd_focus_{in,out} --- input.c | 4 ++-- terminal.c | 4 ++-- terminal.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'terminal.c') diff --git a/input.c b/input.c index ebbcac74..9df9c5dc 100644 --- a/input.c +++ b/input.c @@ -90,7 +90,7 @@ keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, wayl->kbd_focus = wayl_terminal_from_surface(wayl, surface); assert(wayl->kbd_focus != NULL); - term_focus_in(wayl->kbd_focus); + term_kbd_focus_in(wayl->kbd_focus); term_xcursor_update(wayl->kbd_focus); } @@ -157,7 +157,7 @@ keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, * keyboard_leave() (and keyboard_key()) without first having * received a keyboard_enter() */ - term_focus_out(old_focused); + term_kbd_focus_out(old_focused); term_xcursor_update(old_focused); } else { LOG_WARN( diff --git a/terminal.c b/terminal.c index a9ed686f..4e1dd201 100644 --- a/terminal.c +++ b/terminal.c @@ -1392,7 +1392,7 @@ term_restore_cursor(struct terminal *term) } void -term_focus_in(struct terminal *term) +term_kbd_focus_in(struct terminal *term) { if (term->cursor_blink.active) cursor_blink_start_timer(term); @@ -1404,7 +1404,7 @@ term_focus_in(struct terminal *term) } void -term_focus_out(struct terminal *term) +term_kbd_focus_out(struct terminal *term) { if (term->cursor_blink.active) cursor_blink_stop_timer(term); diff --git a/terminal.h b/terminal.h index e4eafe77..301ebad1 100644 --- a/terminal.h +++ b/terminal.h @@ -378,8 +378,8 @@ void term_arm_blink_timer(struct terminal *term); void term_restore_cursor(struct terminal *term); -void term_focus_in(struct terminal *term); -void term_focus_out(struct terminal *term); +void term_kbd_focus_in(struct terminal *term); +void term_kbd_focus_out(struct terminal *term); void term_mouse_down(struct terminal *term, int button, int row, int col); void term_mouse_up(struct terminal *term, int button, int row, int col); void term_mouse_motion(struct terminal *term, int button, int row, int col); -- cgit v1.3 From 6f281cebfb5db24c10a2cd0a10e2175fe9f6b514 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 2 Jan 2020 19:35:32 +0100 Subject: term: add term_visual_focus_{in,out} These functions should be called when the terminal gets or loses visual focus. Note that this isn't necessarily the same as having keyboard focus. --- terminal.c | 25 +++++++++++++++++-------- terminal.h | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 4e1dd201..fe69890d 100644 --- a/terminal.c +++ b/terminal.c @@ -1392,27 +1392,36 @@ term_restore_cursor(struct terminal *term) } void -term_kbd_focus_in(struct terminal *term) +term_visual_focus_in(struct terminal *term) { + term->visual_focus = true; if (term->cursor_blink.active) cursor_blink_start_timer(term); - - if (term->focus_events) - term_to_slave(term, "\033[I", 3); - cursor_refresh(term); } void -term_kbd_focus_out(struct terminal *term) +term_visual_focus_out(struct terminal *term) { + term->visual_focus = false; if (term->cursor_blink.active) cursor_blink_stop_timer(term); + cursor_refresh(term); +} + +void +term_kbd_focus_in(struct terminal *term) +{ if (term->focus_events) - term_to_slave(term, "\033[O", 3); + term_to_slave(term, "\033[I", 3); +} - cursor_refresh(term); +void +term_kbd_focus_out(struct terminal *term) +{ + if (term->focus_events) + term_to_slave(term, "\033[O", 3); } static int diff --git a/terminal.h b/terminal.h index 301ebad1..16323bfb 100644 --- a/terminal.h +++ b/terminal.h @@ -378,6 +378,8 @@ void term_arm_blink_timer(struct terminal *term); void term_restore_cursor(struct terminal *term); +void term_visual_focus_in(struct terminal *term); +void term_visual_focus_out(struct terminal *term); void term_kbd_focus_in(struct terminal *term); void term_kbd_focus_out(struct terminal *term); void term_mouse_down(struct terminal *term, int button, int row, int col); -- cgit v1.3 From 4451f4ad62d4f5117f815e258e3c2cf4fa0fb758 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 11:15:35 +0100 Subject: term: spell 'initialize' correctly --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index fe69890d..8a602925 100644 --- a/terminal.c +++ b/terminal.c @@ -653,7 +653,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, if ((term->slave = slave_spawn(term->ptmx, argc, term->cwd, argv, term_env, conf->shell)) == -1) goto err; - /* Initiailze the Wayland window backend */ + /* Initialize the Wayland window backend */ if ((term->window = wayl_win_init(wayl)) == NULL) goto err; -- cgit v1.3 From 913c684844ad41c8a4b803abd649a9460e3a57dd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 11:16:06 +0100 Subject: term: term_init() calls wl_display_roundtrip() Instead of having `wayl_win_init()` call `wl_display_roundtrip()` (which it itself doesn't need), call it from `term_init()`. This allows us to add ourselves (the new terminal instance) to the terminal list in the wayland backend, before triggering the wayland events caused by `wayl_win_init()`. This is turn allows the wayland backend to find/lookup the new terminal when those events occur.. --- terminal.c | 7 ++++++- wayland.c | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 8a602925..c3697720 100644 --- a/terminal.c +++ b/terminal.c @@ -657,6 +657,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, if ((term->window = wayl_win_init(wayl)) == NULL) goto err; + /* Let the Wayland backend know we exist */ + tll_push_back(wayl->terms, term); + + /* Roundtrip to ensure the wayland window have been configured */ + wl_display_roundtrip(term->wl->display); + term_set_window_title(term, "foot"); /* Try to use user-configured window dimentions */ @@ -675,7 +681,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, height = max(height, term->cell_height); render_resize(term, width, height); - tll_push_back(wayl->terms, term); return term; err: diff --git a/wayland.c b/wayland.c index 7ab1ef2f..816ef1b6 100644 --- a/wayland.c +++ b/wayland.c @@ -804,8 +804,6 @@ wayl_win_init(struct wayland *wayl) wl_subsurface_set_desync(win->search_sub_surface); wl_surface_commit(win->surface); - wl_display_roundtrip(wayl->display); - return win; out: -- cgit v1.3 From 80dfd5b6457a8f44be8b62af1e47284bb8e5c095 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 11:19:56 +0100 Subject: term: visual_focus_{in,out}: do nothing if already focused/defocused --- terminal.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index c3697720..14cbf251 100644 --- a/terminal.c +++ b/terminal.c @@ -1399,6 +1399,9 @@ term_restore_cursor(struct terminal *term) void term_visual_focus_in(struct terminal *term) { + if (term->visual_focus) + return; + term->visual_focus = true; if (term->cursor_blink.active) cursor_blink_start_timer(term); @@ -1408,6 +1411,9 @@ term_visual_focus_in(struct terminal *term) void term_visual_focus_out(struct terminal *term) { + if (!term->visual_focus) + return; + term->visual_focus = false; if (term->cursor_blink.active) cursor_blink_stop_timer(term); -- cgit v1.3 From bd13c2c86a08189d6d5269616634a123f59bde9f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 3 Jan 2020 12:45:30 +0100 Subject: term: render_resize() now takes a 'refresh' argument --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 14cbf251..b31d3867 100644 --- a/terminal.c +++ b/terminal.c @@ -679,7 +679,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, /* Don't go below a single cell */ width = max(width, term->cell_width); height = max(height, term->cell_height); - render_resize(term, width, height); + render_resize(term, width, height, true); return term; -- cgit v1.3