/* * Copyright © 2022 Collabora, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial * portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include #include #include #include #include #include #include #include "shell.h" #include "log.h" #include "main-grpc.h" #include "grpc-async-cb.h" struct shell_data_init { struct agl_shell *shell; bool wait_for_bound; bool bound_ok; bool bound_fail; int version; }; static int running = 1; static void agl_shell_bound_ok_init(void *data, struct agl_shell *agl_shell) { (void) agl_shell; struct shell_data_init *sh = static_cast(data); sh->wait_for_bound = false; sh->bound_ok = true; } static void agl_shell_bound_fail_init(void *data, struct agl_shell *agl_shell) { (void) agl_shell; struct shell_data_init *sh = static_cast(data); sh->wait_for_bound = false; sh->bound_fail = true; } static void agl_shell_bound_ok(void *data, struct agl_shell *agl_shell) { (void) agl_shell; struct shell_data *sh = static_cast(data); sh->wait_for_bound = false; sh->bound_ok = true; } static void agl_shell_bound_fail(void *data, struct agl_shell *agl_shell) { (void) agl_shell; struct shell_data *sh = static_cast(data); sh->wait_for_bound = false; sh->bound_ok = false; } static void agl_shell_app_state(void *data, struct agl_shell *agl_shell, const char *app_id, uint32_t state) { (void) agl_shell; struct shell_data *sh = static_cast(data); LOG("got app_state event app_id %s, state %d\n", app_id, state); if (sh->server_context_list.empty()) return; ::agl_shell_ipc::AppStateResponse app; sh->current_app_state.set_app_id(std::string(app_id)); sh->current_app_state.set_state(state); auto start = sh->server_context_list.begin(); while (start != sh->server_context_list.end()) { // hold on if we're still detecting another in-flight writting if (start->second->Writting()) { LOG("skip writing to lister %p\n", static_cast(start->second)); continue; } LOG("writing to lister %p\n", static_cast(start->second)); start->second->NextWrite(); start++; } } static const struct agl_shell_listener shell_listener = { agl_shell_bound_ok, agl_shell_bound_fail, agl_shell_app_state, }; static const struct agl_shell_listener shell_listener_init = { agl_shell_bound_ok_init, agl_shell_bound_fail_init, nullptr, }; static void agl_shell_ext_doas_done(void *data, struct agl_shell_ext *agl_shell_ext, uint32_t status) { (void) agl_shell_ext; struct shell_data *sh = static_cast(data); sh->wait_for_doas = false; if (status == AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_SUCCESS) sh->doas_ok = true; } static const struct agl_shell_ext_listener shell_ext_listener = { agl_shell_ext_doas_done, }; static void display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y, int physical_width, int physical_height, int subpixel, const char *make, const char *model, int transform) { (void) data; (void) wl_output; (void) x; (void) y; (void) physical_width; (void) physical_height; (void) subpixel; (void) make; (void) model; (void) transform; } static void display_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags, int width, int height, int refresh) { (void) data; (void) wl_output; (void) flags; (void) width; (void) height; (void) refresh; } static void display_handle_done(void *data, struct wl_output *wl_output) { (void) data; (void) wl_output; } static void display_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) { (void) data; (void) wl_output; (void) factor; } static void display_handle_name(void *data, struct wl_output *wl_output, const char *name) { (void) wl_output; struct window_output *woutput = static_cast(data); woutput->name = strdup(name); } static void display_handle_description(void *data, struct wl_output *wl_output, const char *description) { (void) data; (void) wl_output; (void) description; } static const struct wl_output_listener output_listener = { display_handle_geometry, display_handle_mode, display_handle_done, display_handle_scale, display_handle_name, display_handle_description, }; static void display_add_output(struct shell_data *sh, struct wl_registry *reg, uint32_t id, uint32_t version) { struct window_output *w_output; w_output = new struct window_output; w_output->shell_data = sh; w_output->output = static_cast(wl_registry_bind(reg, id, &wl_output_interface, std::min(version, static_cast(4)))); wl_list_insert(&sh->output_list, &w_output->link); wl_output_add_listener(w_output->output, &output_listener, w_output); } static void destroy_output(struct window_output *w_output) { free(w_output->name); wl_list_remove(&w_output->link); free(w_output); } static void global_add(void *data, struct wl_registry *reg, uint32_t id, const char *interface, uint32_t version) { struct shell_data *sh = static_cast(data); if (!sh) return; if (strcmp(interface, agl_shell_interfa