ui: Fix ui resizing and change some method names

This commit is contained in:
Thiago de Arruda
2014-12-13 12:58:06 -03:00
parent 9b30abcecb
commit 213c3c3e53
4 changed files with 63 additions and 53 deletions

View File

@@ -27,12 +27,15 @@ void remote_ui_init(void)
{
connected_uis = pmap_new(uint64_t)();
// 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};
msgpack_rpc_add_method_handler(method, handler);
method = cstr_as_string("detach_ui");
method = cstr_as_string("ui_detach");
handler.fn = remote_ui_detach;
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)
@@ -95,7 +98,6 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,
ui->suspend = remote_ui_suspend;
pmap_put(uint64_t)(connected_uis, channel_id, ui);
ui_attach(ui);
return NIL;
}
@@ -110,6 +112,30 @@ static Object remote_ui_detach(uint64_t channel_id, uint64_t request_id,
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)
{
Array call = ARRAY_DICT_INIT;