mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
t/ctl: Refactor code to make more tidy
This commit is contained in:
parent
4e6a137c62
commit
7b9d7091bd
|
@ -20,9 +20,76 @@ typedef enum op_mode
|
||||||
MODE_GET,
|
MODE_GET,
|
||||||
MODE_SET_PRIMARY,
|
MODE_SET_PRIMARY,
|
||||||
MODE_SET_FOCUSED,
|
MODE_SET_FOCUSED,
|
||||||
|
|
||||||
} op_mode_t;
|
} op_mode_t;
|
||||||
|
|
||||||
|
int
|
||||||
|
get_mode(struct ipc_connection *ipc_c)
|
||||||
|
{
|
||||||
|
struct ipc_client_list clients;
|
||||||
|
|
||||||
|
xrt_result_t r;
|
||||||
|
|
||||||
|
r = ipc_call_system_get_clients(ipc_c, &clients);
|
||||||
|
if (r != XRT_SUCCESS) {
|
||||||
|
printf("failed to get client list.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) {
|
||||||
|
if (clients.ids[i] < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ipc_app_state cs;
|
||||||
|
r = ipc_call_system_get_client_info(ipc_c, i, &cs);
|
||||||
|
if (r != XRT_SUCCESS) {
|
||||||
|
printf(
|
||||||
|
"failed to get client info "
|
||||||
|
"for client %d.\n",
|
||||||
|
i);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(
|
||||||
|
"id: %d\tact: %d\tdisp: "
|
||||||
|
"%d\tfoc: %d\tovly: %d\tz: "
|
||||||
|
"%d\tpid: "
|
||||||
|
"%d\t %s\t\n",
|
||||||
|
clients.ids[i], cs.session_active, cs.session_visible,
|
||||||
|
cs.session_focused, cs.session_overlay, cs.z_order, cs.pid,
|
||||||
|
cs.info.application_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
set_primary(struct ipc_connection *ipc_c, int client_id)
|
||||||
|
{
|
||||||
|
xrt_result_t r;
|
||||||
|
|
||||||
|
r = ipc_call_system_set_primary_client(ipc_c, client_id);
|
||||||
|
if (r != XRT_SUCCESS) {
|
||||||
|
printf("failed to set active client to %d.\n", client_id);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
set_focused(struct ipc_connection *ipc_c, int client_id)
|
||||||
|
{
|
||||||
|
xrt_result_t r;
|
||||||
|
|
||||||
|
r = ipc_call_system_set_focused_client(ipc_c, client_id);
|
||||||
|
if (r != XRT_SUCCESS) {
|
||||||
|
printf("failed to set focused client to %d.\n", client_id);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
|
@ -99,69 +166,24 @@ main(int argc, char *argv[])
|
||||||
sizeof(cs.info.application_name), "%s", "monado-ctl");
|
sizeof(cs.info.application_name), "%s", "monado-ctl");
|
||||||
|
|
||||||
xrt_result_t r = ipc_call_system_set_client_info(&ipc_c, &cs);
|
xrt_result_t r = ipc_call_system_set_client_info(&ipc_c, &cs);
|
||||||
|
|
||||||
if (r != XRT_SUCCESS) {
|
if (r != XRT_SUCCESS) {
|
||||||
printf("failed to set client info.\n");
|
printf("failed to set client info.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (op_mode) {
|
switch (op_mode) {
|
||||||
case MODE_GET: {
|
case MODE_GET:
|
||||||
|
exit(get_mode(&ipc_c));
|
||||||
struct ipc_client_list clients;
|
break;
|
||||||
xrt_result_t r =
|
case MODE_SET_PRIMARY:
|
||||||
ipc_call_system_get_clients(&ipc_c, &clients);
|
exit(set_primary(&ipc_c, s_val));
|
||||||
if (r != XRT_SUCCESS) {
|
break;
|
||||||
printf("failed to get client list.\n");
|
case MODE_SET_FOCUSED:
|
||||||
exit(1);
|
exit(set_focused(&ipc_c, s_val));
|
||||||
}
|
break;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) {
|
|
||||||
if (clients.ids[i] >= 0) {
|
|
||||||
struct ipc_app_state cs;
|
|
||||||
xrt_result_t r =
|
|
||||||
ipc_call_system_get_client_info(
|
|
||||||
&ipc_c, i, &cs);
|
|
||||||
if (r != XRT_SUCCESS) {
|
|
||||||
printf(
|
|
||||||
"failed to get client info "
|
|
||||||
"for client %d.\n",
|
|
||||||
i);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf(
|
|
||||||
"id: %d\tact: %d\tdisp: "
|
|
||||||
"%d\tfoc: %d\tovly: %d\tz: "
|
|
||||||
"%d\tpid: "
|
|
||||||
"%d\t %s\t\n",
|
|
||||||
clients.ids[i], cs.session_active,
|
|
||||||
cs.session_visible,
|
|
||||||
cs.session_focused,
|
|
||||||
cs.session_overlay, cs.z_order,
|
|
||||||
cs.pid, cs.info.application_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} break;
|
|
||||||
case MODE_SET_PRIMARY: {
|
|
||||||
xrt_result_t r =
|
|
||||||
ipc_call_system_set_primary_client(&ipc_c, s_val);
|
|
||||||
if (r != XRT_SUCCESS) {
|
|
||||||
printf("failed to set active client to %d.\n",
|
|
||||||
s_val);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case MODE_SET_FOCUSED: {
|
|
||||||
xrt_result_t r =
|
|
||||||
ipc_call_system_set_focused_client(&ipc_c, s_val);
|
|
||||||
if (r != XRT_SUCCESS) {
|
|
||||||
printf("failed to set focused client to %d.\n",
|
|
||||||
s_val);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
default: printf("Unrecognised operation mode.\n"); exit(1);
|
default: printf("Unrecognised operation mode.\n"); exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue