diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-12-15 08:25:53 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-12-15 08:25:53 -0500 |
commit | b76acbaf4f0ad4facdedeeb9a6618f1b68047c46 (patch) | |
tree | 940bbfe5bdfed32ff2e2fe1453dd6fa5ae296cf1 | |
parent | Merge pull request #327 from mikkeloscar/bar-colors (diff) | |
download | sway-b76acbaf4f0ad4facdedeeb9a6618f1b68047c46.tar.gz sway-b76acbaf4f0ad4facdedeeb9a6618f1b68047c46.tar.zst sway-b76acbaf4f0ad4facdedeeb9a6618f1b68047c46.zip |
Implement IPC_GET_BAR_CONFIG
-rw-r--r-- | sway/ipc-server.c | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 3f02812d..727f06da 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -347,7 +347,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
347 | json_object_object_add(json, "patch", json_object_new_int(0)); | 347 | json_object_object_add(json, "patch", json_object_new_int(0)); |
348 | #endif | 348 | #endif |
349 | const char *json_string = json_object_to_json_string(json); | 349 | const char *json_string = json_object_to_json_string(json); |
350 | ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); | 350 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); |
351 | json_object_put(json); // free | 351 | json_object_put(json); // free |
352 | free(full_version); | 352 | free(full_version); |
353 | break; | 353 | break; |
@@ -366,6 +366,97 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
366 | wlc_output_get_pixels(output->handle, get_pixels_callback, client); | 366 | wlc_output_get_pixels(output->handle, get_pixels_callback, client); |
367 | break; | 367 | break; |
368 | } | 368 | } |
369 | case IPC_GET_BAR_CONFIG: | ||
370 | { | ||
371 | buf[client->payload_length] = '\0'; | ||
372 | if (!buf[0]) { | ||
373 | // Send list of configured bar IDs | ||
374 | json_object *bars = json_object_new_array(); | ||
375 | int i; | ||
376 | for (i = 0; i < config->bars->length; ++i) { | ||
377 | struct bar_config *bar = config->bars->items[i]; | ||
378 | json_object_array_add(bars, json_object_new_string(bar->id)); | ||
379 | } | ||
380 | const char *json_string = json_object_to_json_string(bars); | ||
381 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
382 | json_object_put(bars); // free | ||
383 | } else { | ||
384 | // Send particular bar's details | ||
385 | buf[client->payload_length] = '\0'; | ||
386 | struct bar_config *bar = NULL; | ||
387 | int i; | ||
388 | for (i = 0; i < config->bars->length; ++i) { | ||
389 | bar = config->bars->items[i]; | ||
390 | if (strcmp(buf, bar->id) == 0) { | ||
391 | break; | ||
392 | } | ||
393 | bar = NULL; | ||
394 | } | ||
395 | if (!bar) { | ||
396 | const char *error = "{ \"success\": false, \"error\": \"No bar with that ID\" }"; | ||
397 | ipc_send_reply(client, error, (uint32_t)strlen(error)); | ||
398 | break; | ||
399 | } | ||
400 | json_object *json = json_object_new_object(); | ||
401 | json_object_object_add(json, "id", json_object_new_string(bar->id)); | ||
402 | json_object_object_add(json, "tray_output", NULL); | ||
403 | json_object_object_add(json, "mode", json_object_new_string(bar->mode)); | ||
404 | json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state)); | ||
405 | //json_object_object_add(json, "modifier", json_object_new_string(bar->modifier)); // TODO: Fix modifier | ||
406 | switch (bar->position) { | ||
407 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | ||
408 | json_object_object_add(json, "position", json_object_new_string("top")); | ||
409 | break; | ||
410 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: | ||
411 | json_object_object_add(json, "position", json_object_new_string("bottom")); | ||
412 | break; | ||
413 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: | ||
414 | json_object_object_add(json, "position", json_object_new_string("left")); | ||
415 | break; | ||
416 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: | ||
417 | json_object_object_add(json, "position", json_object_new_string("right")); | ||
418 | break; | ||
419 | } | ||
420 | json_object_object_add(json, "status_command", json_object_new_string(bar->status_command)); | ||
421 | json_object_object_add(json, "font", json_object_new_string(bar->font)); | ||
422 | json_object_object_add(json, "bar_height", json_object_new_int(bar->bar_height)); | ||
423 | json_object_object_add(json, "workspace_buttons", json_object_new_boolean(bar->workspace_buttons)); | ||
424 | json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); | ||
425 | json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); | ||
426 | json_object_object_add(json, "verbose", json_object_new_boolean(bar->verbose)); | ||
427 | |||
428 | json_object *colors = json_object_new_object(); | ||
429 | json_object_object_add(colors, "background", json_object_new_string(bar->colors.background)); | ||
430 | json_object_object_add(colors, "statusline", json_object_new_string(bar->colors.statusline)); | ||
431 | json_object_object_add(colors, "separator", json_object_new_string(bar->colors.separator)); | ||
432 | |||
433 | json_object_object_add(colors, "focused_workspace_border", json_object_new_string(bar->colors.focused_workspace_border)); | ||
434 | json_object_object_add(colors, "focused_workspace_bg", json_object_new_string(bar->colors.focused_workspace_bg)); | ||
435 | json_object_object_add(colors, "focused_workspace_text", json_object_new_string(bar->colors.focused_workspace_text)); | ||
436 | |||
437 | json_object_object_add(colors, "inactive_workspace_border", json_object_new_string(bar->colors.inactive_workspace_border)); | ||
438 | json_object_object_add(colors, "inactive_workspace_bg", json_object_new_string(bar->colors.inactive_workspace_bg)); | ||
439 | json_object_object_add(colors, "inactive_workspace_text", json_object_new_string(bar->colors.inactive_workspace_text)); | ||
440 | |||
441 | json_object_object_add(colors, "active_workspace_border", json_object_new_string(bar->colors.active_workspace_border)); | ||
442 | json_object_object_add(colors, "active_workspace_bg", json_object_new_string(bar->colors.active_workspace_bg)); | ||
443 | json_object_object_add(colors, "active_workspace_text", json_object_new_string(bar->colors.active_workspace_text)); | ||
444 | |||
445 | json_object_object_add(colors, "urgent_workspace_border", json_object_new_string(bar->colors.urgent_workspace_border)); | ||
446 | json_object_object_add(colors, "urgent_workspace_bg", json_object_new_string(bar->colors.urgent_workspace_bg)); | ||
447 | json_object_object_add(colors, "urgent_workspace_text", json_object_new_string(bar->colors.urgent_workspace_text)); | ||
448 | |||
449 | json_object_object_add(colors, "binding_mode_border", json_object_new_string(bar->colors.binding_mode_border)); | ||
450 | json_object_object_add(colors, "binding_mode_bg", json_object_new_string(bar->colors.binding_mode_bg)); | ||
451 | json_object_object_add(colors, "binding_mode_text", json_object_new_string(bar->colors.binding_mode_text)); | ||
452 | |||
453 | json_object_object_add(json, "colors", colors); | ||
454 | |||
455 | const char *json_string = json_object_to_json_string(json); | ||
456 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
457 | json_object_put(json); // free | ||
458 | } | ||
459 | } | ||
369 | default: | 460 | default: |
370 | sway_log(L_INFO, "Unknown IPC command type %i", client->current_command); | 461 | sway_log(L_INFO, "Unknown IPC command type %i", client->current_command); |
371 | ipc_client_disconnect(client); | 462 | ipc_client_disconnect(client); |