std::string g_titled_component::getTitle() { if (!g_ui_initialized) { return 0; } // send initialization request uint32_t tx = g_ipc_next_topic(); g_ui_component_get_title_request request; request.header.id = G_UI_PROTOCOL_SET_TITLE; request.id = this->id; g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_get_title_request), tx); // read response size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_title_response); g_local<uint8_t> buffer(new uint8_t[bufferSize]); if (g_receive_message_t(buffer(), bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { g_ui_component_get_title_response* response = (g_ui_component_get_title_response*) G_MESSAGE_CONTENT(buffer()); if (response->status == G_UI_PROTOCOL_SUCCESS) { return std::string(response->title); } } return std::string(); }
void g_mouse::registerMouse() { uint32_t ps2driverid = g_task_get_id(G_PS2_DRIVER_IDENTIFIER); if (ps2driverid == -1) { return; } mouseTopic = g_ipc_next_topic(); g_ps2_register_request request; request.command = G_PS2_COMMAND_REGISTER_MOUSE; g_send_message_t(ps2driverid, &request, sizeof(g_ps2_register_request), mouseTopic); }
bool g_titled_component::setTitle(std::string title) { if (!g_ui_initialized) { return 0; } // send initialization request uint32_t tx = g_ipc_next_topic(); g_local<g_ui_component_set_title_request> request(new g_ui_component_set_title_request()); request()->header.id = G_UI_PROTOCOL_SET_TITLE; request()->id = this->id; // fill text (truncate if necessary) const char* title_str = title.c_str(); size_t title_len; if (title.length() >= G_UI_COMPONENT_TITLE_MAXIMUM) { title_len = G_UI_COMPONENT_TITLE_MAXIMUM; } else { title_len = title.length(); } memcpy(request()->title, title.c_str(), title_len); request()->title[title_len] = 0; g_send_message_t(g_ui_delegate_tid, request(), sizeof(g_ui_component_set_title_request), tx); // read response size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_title_response); uint8_t buffer[bufferSize]; if (g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { g_ui_component_set_title_response* response = (g_ui_component_set_title_response*) G_MESSAGE_CONTENT(buffer); if (response->status == G_UI_PROTOCOL_SUCCESS) { return true; } } return false; }
/** * Opens a connection to the window server. */ g_ui_open_status g_ui::open() { // check if already open if (g_ui_ready) { return G_UI_OPEN_STATUS_EXISTING; } // get window managers id g_tid window_mgr = g_task_get_id(G_WINDOW_MANAGER_IDENTIFIER); if (window_mgr == -1) { g_logger::log("failed to retrieve task id of window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // open in/out pipes g_fs_pipe_status status; g_fd g_ui_channel_out_read; g_pipe_s(&g_ui_channel_out, &g_ui_channel_out_read, &status); g_fd g_ui_channel_in_write; g_pipe_s(&g_ui_channel_in_write, &g_ui_channel_in, &status); if (status == G_FS_PIPE_ERROR) { g_logger::log("failed to open UI communication pipe"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // tell window manager to open uint32_t topic = g_ipc_next_topic(); g_message_empty(open_request); open_request.type = G_UI_COMMAND_OPEN_REQUEST; open_request.topic = topic; open_request.parameterA = g_ui_channel_out_read; open_request.parameterB = g_ui_channel_in_write; auto request_status = g_send_msg(window_mgr, &open_request); if (request_status != G_MESSAGE_SEND_STATUS_SUCCESSFUL) { g_logger::log("failed to send UI-open request to window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // wait for response g_message_empty(open_response); auto response_status = g_recv_topic_msg(g_get_tid(), topic, &open_response); if (response_status != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) { g_logger::log("failed to receive UI-open response from window server"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // check response message if (open_response.type != G_UI_COMMAND_OPEN_RESPONSE) { g_logger::log("window servers UI-open response was not a proper 'opened'-response"); return G_UI_OPEN_STATUS_COMMUNICATION_FAILED; } // start asynchronous receiver g_create_thread((void*) &asynchronous_receiver_thread); g_create_thread((void*) &event_dispatch_thread); // mark UI as ready g_logger::log("successfully opened UI in window server"); g_ui_ready = true; return G_UI_OPEN_STATUS_SUCCESSFUL; }