This commit is contained in:
calvinkosmatka 2017-06-12 22:09:16 +00:00 committed by GitHub
commit 4ba22e2bbd
17 changed files with 217 additions and 40 deletions

View file

@ -164,6 +164,15 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
output->output, bar_output->window->surface);
desktop_shell_set_panel_position(bar_output->registry->desktop_shell,
bar->config->position);
switch (bar->config->display_mode) {
case MODE_HIDE:
case MODE_INVISIBLE:
desktop_shell_set_panel_hide_mode(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_MODES_HIDE);
break;
case MODE_DOCK:
desktop_shell_set_panel_hide_mode(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_MODES_SHOW);
break;
}
window_make_shell(bar_output->window);

View file

@ -30,6 +30,28 @@ char *parse_font(const char *font) {
return new_font;
}
enum display_mode_types parse_display_mode(const char *display_mode) {
if (strcmp("hide", display_mode) == 0) {
return MODE_HIDE;
} else if (strcmp("dock", display_mode) == 0) {
return MODE_DOCK;
} else if (strcmp("invisible", display_mode) == 0) {
return MODE_INVISIBLE;
} else {
return MODE_DOCK;
}
}
enum hidden_states parse_hidden_state(const char *hidden_state) {
if (strcmp("show", hidden_state) == 0) {
return BAR_SHOW;
} else if (strcmp("hide", hidden_state) == 0) {
return BAR_HIDDEN;
} else {
return BAR_SHOW;
}
}
struct config *init_config() {
struct config *config = calloc(1, sizeof(struct config));
config->status_command = NULL;
@ -37,6 +59,8 @@ struct config *init_config() {
config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
config->font = strdup("monospace 10");
config->mode = NULL;
config->display_mode = MODE_DOCK;
config->hidden_state = BAR_SHOW;
config->sep_symbol = NULL;
config->strip_workspace_numbers = false;
config->binding_mode_indicator = true;

View file

@ -7,6 +7,7 @@
#include "ipc-client.h"
#include "list.h"
#include "log.h"
#include "util.h"
void ipc_send_workspace_command(const char *workspace_name) {
uint32_t size = strlen("workspace \"\"") + strlen(workspace_name) + 1;
@ -19,13 +20,15 @@ void ipc_send_workspace_command(const char *workspace_name) {
static void ipc_parse_config(struct config *config, const char *payload) {
json_object *bar_config = json_tokener_parse(payload);
json_object *tray_output, *mode, *hidden_bar, *position, *status_command;
json_object *tray_output, *display_mode, *hidden_state, *position, *status_command;
json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers;
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
json_object *markup;
json_object_object_get_ex(bar_config, "tray_output", &tray_output);
json_object_object_get_ex(bar_config, "mode", &mode);
json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar);
// "mode" as in the bar's display mode and "mode" as in binding mode
// should be distinguished more carefully
json_object_object_get_ex(bar_config, "mode", &display_mode);
json_object_object_get_ex(bar_config, "hidden_state", &hidden_state);
json_object_object_get_ex(bar_config, "position", &position);
json_object_object_get_ex(bar_config, "status_command", &status_command);
json_object_object_get_ex(bar_config, "font", &font);
@ -44,6 +47,14 @@ static void ipc_parse_config(struct config *config, const char *payload) {
free(config->status_command);
config->status_command = strdup(json_object_get_string(status_command));
}
if (display_mode) {
config->display_mode = parse_display_mode(strdup(json_object_get_string(display_mode)));
}
if (hidden_state) {
config->hidden_state = parse_hidden_state(strdup(json_object_get_string(hidden_state)));
}
if (position) {
config->position = parse_position(json_object_get_string(position));
@ -322,10 +333,17 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) {
}
free(res);
json_object_put(outputs);
const char *subscribe_json = "[ \"workspace\", \"mode\" ]";
len = strlen(subscribe_json);
res = ipc_single_command(bar->ipc_event_socketfd, IPC_SUBSCRIBE, subscribe_json, &len);
// Will need to be redone for display mode toggling compatibility
// Will require setting bar->config->hidden_state to "show" as default
json_object *subscribe_json = json_object_new_array();
json_object_array_add(subscribe_json, json_object_new_string("workspace"));
json_object_array_add(subscribe_json, json_object_new_string("mode"));
if (bar->config->display_mode == MODE_HIDE) {
json_object_array_add(subscribe_json, json_object_new_string("modifier"));
}
const char *subscribe_json_string = json_object_to_json_string(subscribe_json);
len = strlen(subscribe_json_string);
res = ipc_single_command(bar->ipc_event_socketfd, IPC_SUBSCRIBE, subscribe_json_string, &len);
free(res);
ipc_update_workspaces(bar);
@ -364,6 +382,44 @@ bool handle_ipc_event(struct bar *bar) {
json_object_put(result);
break;
}
case IPC_EVENT_MODIFIER: {
if (bar->config->display_mode == MODE_HIDE) {
json_object *result = json_tokener_parse(resp->payload);
if (!result) {
free_ipc_response(resp);
sway_log(L_ERROR, "failed to parse payload as json");
return false;
}
json_object *json_change;
if (json_object_object_get_ex(result, "change", &json_change)) {
const char *change = json_object_get_string(json_change);
if (strcmp(change, "pressed") == 0) {
bar->config->hidden_state = BAR_SHOW;
sway_log(L_ERROR, "Showing bar on %d outputs", bar->outputs->length);
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *bar_output = bar->outputs->items[i];
sway_log(L_ERROR, "showing bar on input %d, with registry %p", i, bar_output->registry);
desktop_shell_set_panel_hide(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_STATE_SHOW);
}
} else { //must be "released"
bar->config->hidden_state = BAR_HIDDEN;
sway_log(L_ERROR, "Hiding bar");
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *bar_output = bar->outputs->items[i];
desktop_shell_set_panel_hide(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_STATE_HIDE);
}
}
} else {
sway_log(L_ERROR, "failed to parse response");
}
json_object_put(result);
break;
}
}
default:
free_ipc_response(resp);
return false;

View file

@ -286,9 +286,8 @@ void render(struct output *output, struct config *config, struct status_line *li
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
cairo_paint(cairo);
cairo_restore(cairo);
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
// Background
if (is_focused) {
cairo_set_source_u32(cairo, config->colors.focused_background);