mirror of
https://github.com/swaywm/sway.git
synced 2026-04-29 06:46:22 -04:00
progress on panel protocol
This commit is contained in:
parent
b7fe2a95ca
commit
aea0d45c9d
7 changed files with 168 additions and 92 deletions
|
|
@ -163,6 +163,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);
|
||||
|
||||
|
|
|
|||
|
|
@ -383,27 +383,42 @@ bool handle_ipc_event(struct bar *bar) {
|
|||
break;
|
||||
}
|
||||
case IPC_EVENT_MODIFIER: {
|
||||
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;
|
||||
} else { //must be "released"
|
||||
bar->config->hidden_state = BAR_HIDDEN;
|
||||
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;
|
||||
}
|
||||
|
||||
} else {
|
||||
sway_log(L_ERROR, "failed to parse response");
|
||||
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;
|
||||
}
|
||||
|
||||
json_object_put(result);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
free_ipc_response(resp);
|
||||
|
|
|
|||
109
swaybar/render.c
109
swaybar/render.c
|
|
@ -286,67 +286,58 @@ 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);
|
||||
// Could also be done by always rendering then conditionally clearing and drawing alpha
|
||||
// That may be preferable down the line
|
||||
if (!(config->display_mode == MODE_HIDE) || config->hidden_state == BAR_SHOW) {
|
||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||
|
||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||
|
||||
// Background
|
||||
if (is_focused) {
|
||||
cairo_set_source_u32(cairo, config->colors.focused_background);
|
||||
} else {
|
||||
cairo_set_source_u32(cairo, config->colors.background);
|
||||
}
|
||||
cairo_paint(cairo);
|
||||
|
||||
// Command output
|
||||
if (is_focused) {
|
||||
cairo_set_source_u32(cairo, config->colors.focused_statusline);
|
||||
} else {
|
||||
cairo_set_source_u32(cairo, config->colors.statusline);
|
||||
}
|
||||
|
||||
int width, height;
|
||||
|
||||
if (line->protocol == TEXT) {
|
||||
get_text_size(window->cairo, window->font, &width, &height,
|
||||
window->scale, config->pango_markup, "%s", line->text_line);
|
||||
cairo_move_to(cairo, (window->width * window->scale)
|
||||
- margin - width, margin);
|
||||
pango_printf(window->cairo, window->font, window->scale,
|
||||
config->pango_markup, "%s", line->text_line);
|
||||
} else if (line->protocol == I3BAR && line->block_line) {
|
||||
double pos = (window->width * window->scale) - 0.5;
|
||||
bool edge = true;
|
||||
for (i = line->block_line->length - 1; i >= 0; --i) {
|
||||
struct status_block *block = line->block_line->items[i];
|
||||
if (block->full_text && block->full_text[0]) {
|
||||
render_block(window, config, block, &pos, edge, is_focused);
|
||||
edge = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cairo_set_line_width(cairo, 1.0);
|
||||
double x = 0.5;
|
||||
|
||||
// Workspaces
|
||||
if (config->workspace_buttons) {
|
||||
for (i = 0; i < output->workspaces->length; ++i) {
|
||||
struct workspace *ws = output->workspaces->items[i];
|
||||
render_workspace_button(window, config, ws, &x);
|
||||
}
|
||||
}
|
||||
|
||||
// binding mode indicator
|
||||
if (config->mode && config->binding_mode_indicator) {
|
||||
render_binding_mode_indicator(window, config, x);
|
||||
}
|
||||
// Background
|
||||
if (is_focused) {
|
||||
cairo_set_source_u32(cairo, config->colors.focused_background);
|
||||
} else {
|
||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_u32(cairo, 0x00000000);
|
||||
cairo_paint(cairo);
|
||||
cairo_set_source_u32(cairo, config->colors.background);
|
||||
}
|
||||
cairo_paint(cairo);
|
||||
|
||||
// Command output
|
||||
if (is_focused) {
|
||||
cairo_set_source_u32(cairo, config->colors.focused_statusline);
|
||||
} else {
|
||||
cairo_set_source_u32(cairo, config->colors.statusline);
|
||||
}
|
||||
|
||||
int width, height;
|
||||
|
||||
if (line->protocol == TEXT) {
|
||||
get_text_size(window->cairo, window->font, &width, &height,
|
||||
window->scale, config->pango_markup, "%s", line->text_line);
|
||||
cairo_move_to(cairo, (window->width * window->scale)
|
||||
- margin - width, margin);
|
||||
pango_printf(window->cairo, window->font, window->scale,
|
||||
config->pango_markup, "%s", line->text_line);
|
||||
} else if (line->protocol == I3BAR && line->block_line) {
|
||||
double pos = (window->width * window->scale) - 0.5;
|
||||
bool edge = true;
|
||||
for (i = line->block_line->length - 1; i >= 0; --i) {
|
||||
struct status_block *block = line->block_line->items[i];
|
||||
if (block->full_text && block->full_text[0]) {
|
||||
render_block(window, config, block, &pos, edge, is_focused);
|
||||
edge = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cairo_set_line_width(cairo, 1.0);
|
||||
double x = 0.5;
|
||||
|
||||
// Workspaces
|
||||
if (config->workspace_buttons) {
|
||||
for (i = 0; i < output->workspaces->length; ++i) {
|
||||
struct workspace *ws = output->workspaces->items[i];
|
||||
render_workspace_button(window, config, ws, &x);
|
||||
}
|
||||
}
|
||||
|
||||
// binding mode indicator
|
||||
if (config->mode && config->binding_mode_indicator) {
|
||||
render_binding_mode_indicator(window, config, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue