mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ui: Fix ui resizing and change some method names
This commit is contained in:
parent
8c12292a61
commit
926503c84e
@ -27,12 +27,15 @@ void remote_ui_init(void)
|
|||||||
{
|
{
|
||||||
connected_uis = pmap_new(uint64_t)();
|
connected_uis = pmap_new(uint64_t)();
|
||||||
// Add handler for "attach_ui"
|
// Add handler for "attach_ui"
|
||||||
String method = cstr_as_string("attach_ui");
|
String method = cstr_as_string("ui_attach");
|
||||||
MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false};
|
MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false};
|
||||||
msgpack_rpc_add_method_handler(method, handler);
|
msgpack_rpc_add_method_handler(method, handler);
|
||||||
method = cstr_as_string("detach_ui");
|
method = cstr_as_string("ui_detach");
|
||||||
handler.fn = remote_ui_detach;
|
handler.fn = remote_ui_detach;
|
||||||
msgpack_rpc_add_method_handler(method, handler);
|
msgpack_rpc_add_method_handler(method, handler);
|
||||||
|
method = cstr_as_string("ui_try_resize");
|
||||||
|
handler.fn = remote_ui_try_resize;
|
||||||
|
msgpack_rpc_add_method_handler(method, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remote_ui_disconnect(uint64_t channel_id)
|
void remote_ui_disconnect(uint64_t channel_id)
|
||||||
@ -95,7 +98,6 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,
|
|||||||
ui->suspend = remote_ui_suspend;
|
ui->suspend = remote_ui_suspend;
|
||||||
pmap_put(uint64_t)(connected_uis, channel_id, ui);
|
pmap_put(uint64_t)(connected_uis, channel_id, ui);
|
||||||
ui_attach(ui);
|
ui_attach(ui);
|
||||||
|
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +112,30 @@ static Object remote_ui_detach(uint64_t channel_id, uint64_t request_id,
|
|||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Object remote_ui_try_resize(uint64_t channel_id, uint64_t request_id,
|
||||||
|
Array args, Error *error)
|
||||||
|
{
|
||||||
|
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||||
|
api_set_error(error, Exception, _("UI is not attached for channel"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size != 2 || args.items[0].type != kObjectTypeInteger
|
||||||
|
|| args.items[1].type != kObjectTypeInteger
|
||||||
|
|| args.items[0].data.integer <= 0 || args.items[1].data.integer <= 0) {
|
||||||
|
api_set_error(error, Validation,
|
||||||
|
_("Arguments must be a pair of positive integers "
|
||||||
|
"representing the remote screen width/height"));
|
||||||
|
return NIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
|
||||||
|
ui->width = (int)args.items[0].data.integer;
|
||||||
|
ui->height = (int)args.items[1].data.integer;
|
||||||
|
ui_refresh();
|
||||||
|
return NIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void push_call(UI *ui, char *name, Array args)
|
static void push_call(UI *ui, char *name, Array args)
|
||||||
{
|
{
|
||||||
Array call = ARRAY_DICT_INIT;
|
Array call = ARRAY_DICT_INIT;
|
||||||
|
@ -6519,7 +6519,6 @@ do_highlight (
|
|||||||
|
|
||||||
if (is_normal_group) {
|
if (is_normal_group) {
|
||||||
normal_fg = HL_TABLE()[idx].sg_rgb_fg;
|
normal_fg = HL_TABLE()[idx].sg_rgb_fg;
|
||||||
ui_fg_updated();
|
|
||||||
}
|
}
|
||||||
} else if (STRCMP(key, "GUIBG") == 0) {
|
} else if (STRCMP(key, "GUIBG") == 0) {
|
||||||
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) {
|
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) {
|
||||||
@ -6538,7 +6537,6 @@ do_highlight (
|
|||||||
|
|
||||||
if (is_normal_group) {
|
if (is_normal_group) {
|
||||||
normal_bg = HL_TABLE()[idx].sg_rgb_bg;
|
normal_bg = HL_TABLE()[idx].sg_rgb_bg;
|
||||||
ui_bg_updated();
|
|
||||||
}
|
}
|
||||||
} else if (STRCMP(key, "GUISP") == 0) {
|
} else if (STRCMP(key, "GUISP") == 0) {
|
||||||
// Ignored
|
// Ignored
|
||||||
@ -6635,6 +6633,10 @@ do_highlight (
|
|||||||
if (is_normal_group) {
|
if (is_normal_group) {
|
||||||
HL_TABLE()[idx].sg_term_attr = 0;
|
HL_TABLE()[idx].sg_term_attr = 0;
|
||||||
HL_TABLE()[idx].sg_cterm_attr = 0;
|
HL_TABLE()[idx].sg_cterm_attr = 0;
|
||||||
|
if (abstract_ui) {
|
||||||
|
// If the normal group has changed, it is simpler to refresh every UI
|
||||||
|
ui_refresh();
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
set_hl_attr(idx);
|
set_hl_attr(idx);
|
||||||
HL_TABLE()[idx].sg_scriptID = current_SID;
|
HL_TABLE()[idx].sg_scriptID = current_SID;
|
||||||
|
@ -64,7 +64,7 @@ static HlAttrs current_attrs = {
|
|||||||
false, false, false, false, false, false, -1, -1
|
false, false, false, false, false, false, -1, -1
|
||||||
};
|
};
|
||||||
static bool cursor_enabled = true;
|
static bool cursor_enabled = true;
|
||||||
static int height = INT_MAX, width = INT_MAX;
|
static int height, width;
|
||||||
|
|
||||||
// This set of macros allow us to use UI_CALL to invoke any function on
|
// This set of macros allow us to use UI_CALL to invoke any function on
|
||||||
// registered UI instances. The functions can have 0-5 arguments(configurable
|
// registered UI instances. The functions can have 0-5 arguments(configurable
|
||||||
@ -113,18 +113,6 @@ void ui_write(uint8_t *s, int len)
|
|||||||
free(tofree);
|
free(tofree);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_fg_updated(void)
|
|
||||||
{
|
|
||||||
UI_CALL(update_fg, normal_fg);
|
|
||||||
UI_CALL(flush);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_bg_updated(void)
|
|
||||||
{
|
|
||||||
UI_CALL(update_bg, normal_bg);
|
|
||||||
UI_CALL(flush);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the machine has job control, use it to suspend the program,
|
* If the machine has job control, use it to suspend the program,
|
||||||
* otherwise fake it by starting a new shell.
|
* otherwise fake it by starting a new shell.
|
||||||
@ -177,10 +165,36 @@ void ui_cursor_shape(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_resize(int width, int height)
|
void ui_refresh(void)
|
||||||
{
|
{
|
||||||
ui_fg_updated();
|
if (!ui_count) {
|
||||||
ui_bg_updated();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
width = height = INT_MAX;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ui_count; i++) {
|
||||||
|
UI *ui = uis[i];
|
||||||
|
width = ui->width < width ? ui->width : width;
|
||||||
|
height = ui->height < height ? ui->height : height;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen_resize(width, height, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_resize(int new_width, int new_height)
|
||||||
|
{
|
||||||
|
width = new_width;
|
||||||
|
height = new_height;
|
||||||
|
|
||||||
|
if (normal_fg != -1) {
|
||||||
|
UI_CALL(update_fg, normal_fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (normal_bg != -1) {
|
||||||
|
UI_CALL(update_bg, normal_bg);
|
||||||
|
}
|
||||||
|
|
||||||
sr.top = 0;
|
sr.top = 0;
|
||||||
sr.bot = height - 1;
|
sr.bot = height - 1;
|
||||||
sr.left = 0;
|
sr.left = 0;
|
||||||
@ -254,7 +268,7 @@ void ui_attach(UI *ui)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uis[ui_count++] = ui;
|
uis[ui_count++] = ui;
|
||||||
resized(ui);
|
ui_refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_detach(UI *ui)
|
void ui_detach(UI *ui)
|
||||||
@ -281,17 +295,8 @@ void ui_detach(UI *ui)
|
|||||||
|
|
||||||
ui_count--;
|
ui_count--;
|
||||||
|
|
||||||
if (ui->width == width || ui->height == height) {
|
|
||||||
// It is possible that the UI being detached had the smallest screen,
|
|
||||||
// so check for the new minimum dimensions
|
|
||||||
width = height = INT_MAX;
|
|
||||||
for (size_t i = 0; i < ui_count; i++) {
|
|
||||||
check_dimensions(uis[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ui_count) {
|
if (ui_count) {
|
||||||
screen_resize(width, height, true);
|
ui_refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,25 +479,6 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len)
|
|||||||
UI_CALL(flush);
|
UI_CALL(flush);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resized(UI *ui)
|
|
||||||
{
|
|
||||||
check_dimensions(ui);
|
|
||||||
screen_resize(width, height, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void check_dimensions(UI *ui)
|
|
||||||
{
|
|
||||||
// The internal screen dimensions are always the minimum required to fit on
|
|
||||||
// all connected screens
|
|
||||||
if (ui->width < width) {
|
|
||||||
width = ui->width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ui->height < height) {
|
|
||||||
height = ui->height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ui_linefeed(void)
|
static void ui_linefeed(void)
|
||||||
{
|
{
|
||||||
int new_col = 0;
|
int new_col = 0;
|
||||||
|
@ -115,12 +115,12 @@ function Screen:set_default_attr_ids(attr_ids)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Screen:attach()
|
function Screen:attach()
|
||||||
request('attach_ui', self._width, self._height)
|
request('ui_attach', self._width, self._height)
|
||||||
self._suspended = false
|
self._suspended = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:detach()
|
function Screen:detach()
|
||||||
request('detach_ui')
|
request('ui_detach')
|
||||||
self._suspended = true
|
self._suspended = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user