mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 16:36:26 +01:00
Merge pull request #2723 from ianyfan/swaybar
swaybar: small fixes and clean-ups
This commit is contained in:
commit
ca7084cb52
11 changed files with 124 additions and 101 deletions
|
@ -54,7 +54,6 @@ struct swaybar {
|
||||||
struct wl_seat *seat;
|
struct wl_seat *seat;
|
||||||
|
|
||||||
struct swaybar_config *config;
|
struct swaybar_config *config;
|
||||||
struct swaybar_output *focused_output;
|
|
||||||
struct swaybar_pointer pointer;
|
struct swaybar_pointer pointer;
|
||||||
struct status_line *status;
|
struct status_line *status;
|
||||||
|
|
||||||
|
@ -95,9 +94,7 @@ struct swaybar_workspace {
|
||||||
bool urgent;
|
bool urgent;
|
||||||
};
|
};
|
||||||
|
|
||||||
void bar_setup(struct swaybar *bar,
|
bool bar_setup(struct swaybar *bar, const char *socket_path, const char *bar_id);
|
||||||
const char *socket_path,
|
|
||||||
const char *bar_id);
|
|
||||||
void bar_run(struct swaybar *bar);
|
void bar_run(struct swaybar *bar);
|
||||||
void bar_teardown(struct swaybar *bar);
|
void bar_teardown(struct swaybar *bar);
|
||||||
|
|
||||||
|
|
34
include/swaybar/i3bar.h
Normal file
34
include/swaybar/i3bar.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef _SWAYBAR_I3BAR_H
|
||||||
|
#define _SWAYBAR_I3BAR_H
|
||||||
|
|
||||||
|
#include "bar.h"
|
||||||
|
#include "status_line.h"
|
||||||
|
|
||||||
|
struct i3bar_block {
|
||||||
|
struct wl_list link;
|
||||||
|
int ref_count;
|
||||||
|
char *full_text, *short_text, *align;
|
||||||
|
bool urgent;
|
||||||
|
uint32_t *color;
|
||||||
|
int min_width;
|
||||||
|
char *name, *instance;
|
||||||
|
bool separator;
|
||||||
|
int separator_block_width;
|
||||||
|
bool markup;
|
||||||
|
// Airblader features
|
||||||
|
uint32_t background;
|
||||||
|
uint32_t border;
|
||||||
|
int border_top;
|
||||||
|
int border_bottom;
|
||||||
|
int border_left;
|
||||||
|
int border_right;
|
||||||
|
};
|
||||||
|
|
||||||
|
void i3bar_block_unref(struct i3bar_block *block);
|
||||||
|
bool i3bar_handle_readable(struct status_line *status);
|
||||||
|
enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
|
||||||
|
struct i3bar_block *block, int x, int y, enum x11_button button);
|
||||||
|
enum x11_button wl_button_to_x11_button(uint32_t button);
|
||||||
|
enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value);
|
||||||
|
|
||||||
|
#endif
|
|
@ -3,7 +3,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "swaybar/bar.h"
|
#include "swaybar/bar.h"
|
||||||
|
|
||||||
void ipc_initialize(struct swaybar *bar, const char *bar_id);
|
bool ipc_initialize(struct swaybar *bar, const char *bar_id);
|
||||||
bool handle_ipc_readable(struct swaybar *bar);
|
bool handle_ipc_readable(struct swaybar *bar);
|
||||||
void ipc_get_workspaces(struct swaybar *bar);
|
void ipc_get_workspaces(struct swaybar *bar);
|
||||||
void ipc_send_workspace_command(struct swaybar *bar, const char *ws);
|
void ipc_send_workspace_command(struct swaybar *bar, const char *ws);
|
||||||
|
|
|
@ -13,26 +13,6 @@ enum status_protocol {
|
||||||
PROTOCOL_I3BAR,
|
PROTOCOL_I3BAR,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i3bar_block {
|
|
||||||
struct wl_list link;
|
|
||||||
int ref_count;
|
|
||||||
char *full_text, *short_text, *align;
|
|
||||||
bool urgent;
|
|
||||||
uint32_t *color;
|
|
||||||
int min_width;
|
|
||||||
char *name, *instance;
|
|
||||||
bool separator;
|
|
||||||
int separator_block_width;
|
|
||||||
bool markup;
|
|
||||||
// Airblader features
|
|
||||||
uint32_t background;
|
|
||||||
uint32_t border;
|
|
||||||
int border_top;
|
|
||||||
int border_bottom;
|
|
||||||
int border_left;
|
|
||||||
int border_right;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct status_line {
|
struct status_line {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int read_fd, write_fd;
|
int read_fd, write_fd;
|
||||||
|
@ -55,11 +35,5 @@ struct status_line *status_line_init(char *cmd);
|
||||||
void status_error(struct status_line *status, const char *text);
|
void status_error(struct status_line *status, const char *text);
|
||||||
bool status_handle_readable(struct status_line *status);
|
bool status_handle_readable(struct status_line *status);
|
||||||
void status_line_free(struct status_line *status);
|
void status_line_free(struct status_line *status);
|
||||||
bool i3bar_handle_readable(struct status_line *status);
|
|
||||||
enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
|
|
||||||
struct i3bar_block *block, int x, int y, enum x11_button button);
|
|
||||||
void i3bar_block_unref(struct i3bar_block *block);
|
|
||||||
enum x11_button wl_button_to_x11_button(uint32_t button);
|
|
||||||
enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,7 +21,9 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
|
||||||
config->current_bar->binding_mode_indicator = false;
|
config->current_bar->binding_mode_indicator = false;
|
||||||
wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s",
|
wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s",
|
||||||
config->current_bar->id);
|
config->current_bar->id);
|
||||||
|
} else {
|
||||||
|
return cmd_results_new(CMD_INVALID, "binding_mode_indicator",
|
||||||
|
"Invalid value %s", argv[0]);
|
||||||
}
|
}
|
||||||
return cmd_results_new(CMD_INVALID, "binding_mode_indicator",
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
"Invalid value %s", argv[0]);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
#else
|
#else
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
#endif
|
#endif
|
||||||
#include "swaybar/render.h"
|
#include "swaybar/bar.h"
|
||||||
#include "swaybar/config.h"
|
#include "swaybar/config.h"
|
||||||
#include "swaybar/event_loop.h"
|
#include "swaybar/event_loop.h"
|
||||||
#include "swaybar/status_line.h"
|
#include "swaybar/i3bar.h"
|
||||||
#include "swaybar/bar.h"
|
|
||||||
#include "swaybar/ipc.h"
|
#include "swaybar/ipc.h"
|
||||||
|
#include "swaybar/status_line.h"
|
||||||
|
#include "swaybar/render.h"
|
||||||
#include "ipc-client.h"
|
#include "ipc-client.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -478,14 +479,16 @@ static void render_all_frames(struct swaybar *bar) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bar_setup(struct swaybar *bar,
|
bool bar_setup(struct swaybar *bar,
|
||||||
const char *socket_path, const char *bar_id) {
|
const char *socket_path, const char *bar_id) {
|
||||||
bar_init(bar);
|
bar_init(bar);
|
||||||
init_event_loop();
|
init_event_loop();
|
||||||
|
|
||||||
bar->ipc_socketfd = ipc_open_socket(socket_path);
|
bar->ipc_socketfd = ipc_open_socket(socket_path);
|
||||||
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
|
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
|
||||||
ipc_initialize(bar, bar_id);
|
if (!ipc_initialize(bar, bar_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (bar->config->status_command) {
|
if (bar->config->status_command) {
|
||||||
bar->status = status_line_init(bar->config->status_command);
|
bar->status = status_line_init(bar->config->status_command);
|
||||||
}
|
}
|
||||||
|
@ -526,6 +529,7 @@ void bar_setup(struct swaybar *bar,
|
||||||
|
|
||||||
ipc_get_workspaces(bar);
|
ipc_get_workspaces(bar);
|
||||||
render_all_frames(bar);
|
render_all_frames(bar);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_in(int fd, short mask, void *data) {
|
static void display_in(int fd, short mask, void *data) {
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "swaybar/bar.h"
|
||||||
#include "swaybar/config.h"
|
#include "swaybar/config.h"
|
||||||
|
#include "swaybar/i3bar.h"
|
||||||
#include "swaybar/status_line.h"
|
#include "swaybar/status_line.h"
|
||||||
|
|
||||||
void i3bar_block_unref(struct i3bar_block *block) {
|
void i3bar_block_unref(struct i3bar_block *block) {
|
||||||
|
|
|
@ -141,9 +141,16 @@ static void ipc_parse_colors(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ipc_parse_config(
|
static bool ipc_parse_config(
|
||||||
struct swaybar_config *config, const char *payload) {
|
struct swaybar_config *config, const char *payload) {
|
||||||
json_object *bar_config = json_tokener_parse(payload);
|
json_object *bar_config = json_tokener_parse(payload);
|
||||||
|
json_object *success;
|
||||||
|
if (json_object_object_get_ex(bar_config, "success", &success)
|
||||||
|
&& !json_object_get_boolean(success)) {
|
||||||
|
wlr_log(WLR_ERROR, "No bar with that ID. Use 'swaymsg -t get_bar_config to get the available bar configs.");
|
||||||
|
json_object_put(bar_config);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
json_object *markup, *mode, *hidden_bar, *position, *status_command;
|
json_object *markup, *mode, *hidden_bar, *position, *status_command;
|
||||||
json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers;
|
json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers;
|
||||||
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
|
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
|
||||||
|
@ -226,10 +233,10 @@ static void ipc_parse_config(
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object_put(bar_config);
|
json_object_put(bar_config);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipc_get_workspaces(struct swaybar *bar) {
|
void ipc_get_workspaces(struct swaybar *bar) {
|
||||||
bar->focused_output = NULL;
|
|
||||||
struct swaybar_output *output;
|
struct swaybar_output *output;
|
||||||
wl_list_for_each(output, &bar->outputs, link) {
|
wl_list_for_each(output, &bar->outputs, link) {
|
||||||
free_workspaces(&output->workspaces);
|
free_workspaces(&output->workspaces);
|
||||||
|
@ -312,11 +319,14 @@ static void ipc_get_outputs(struct swaybar *bar) {
|
||||||
free(res);
|
free(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipc_initialize(struct swaybar *bar, const char *bar_id) {
|
bool ipc_initialize(struct swaybar *bar, const char *bar_id) {
|
||||||
uint32_t len = strlen(bar_id);
|
uint32_t len = strlen(bar_id);
|
||||||
char *res = ipc_single_command(bar->ipc_socketfd,
|
char *res = ipc_single_command(bar->ipc_socketfd,
|
||||||
IPC_GET_BAR_CONFIG, bar_id, &len);
|
IPC_GET_BAR_CONFIG, bar_id, &len);
|
||||||
ipc_parse_config(bar->config, res);
|
if (!ipc_parse_config(bar->config, res)) {
|
||||||
|
free(res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
free(res);
|
free(res);
|
||||||
ipc_get_outputs(bar);
|
ipc_get_outputs(bar);
|
||||||
|
|
||||||
|
@ -324,6 +334,7 @@ void ipc_initialize(struct swaybar *bar, const char *bar_id) {
|
||||||
len = strlen(subscribe);
|
len = strlen(subscribe);
|
||||||
free(ipc_single_command(bar->ipc_event_socketfd,
|
free(ipc_single_command(bar->ipc_event_socketfd,
|
||||||
IPC_SUBSCRIBE, subscribe, &len));
|
IPC_SUBSCRIBE, subscribe, &len));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_ipc_readable(struct swaybar *bar) {
|
bool handle_ipc_readable(struct swaybar *bar) {
|
||||||
|
|
|
@ -96,7 +96,10 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
signal(SIGTERM, sig_handler);
|
signal(SIGTERM, sig_handler);
|
||||||
|
|
||||||
bar_setup(&swaybar, socket_path, bar_id);
|
if (!bar_setup(&swaybar, socket_path, bar_id)) {
|
||||||
|
free(socket_path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
free(socket_path);
|
free(socket_path);
|
||||||
free(bar_id);
|
free(bar_id);
|
||||||
|
|
110
swaybar/render.c
110
swaybar/render.c
|
@ -10,6 +10,7 @@
|
||||||
#include "pool-buffer.h"
|
#include "pool-buffer.h"
|
||||||
#include "swaybar/bar.h"
|
#include "swaybar/bar.h"
|
||||||
#include "swaybar/config.h"
|
#include "swaybar/config.h"
|
||||||
|
#include "swaybar/i3bar.h"
|
||||||
#include "swaybar/ipc.h"
|
#include "swaybar/ipc.h"
|
||||||
#include "swaybar/render.h"
|
#include "swaybar/render.h"
|
||||||
#include "swaybar/status_line.h"
|
#include "swaybar/status_line.h"
|
||||||
|
@ -20,47 +21,47 @@ static const double WS_VERTICAL_PADDING = 1.5;
|
||||||
static const double BORDER_WIDTH = 1;
|
static const double BORDER_WIDTH = 1;
|
||||||
|
|
||||||
static uint32_t render_status_line_error(cairo_t *cairo,
|
static uint32_t render_status_line_error(cairo_t *cairo,
|
||||||
struct swaybar_output *output, struct swaybar_config *config,
|
struct swaybar_output *output, double *x) {
|
||||||
const char *error, double *x, uint32_t surface_height) {
|
const char *error = output->bar->status->text;
|
||||||
if (!error) {
|
if (!error) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t height = surface_height * output->scale;
|
uint32_t height = output->height * output->scale;
|
||||||
|
|
||||||
cairo_set_source_u32(cairo, 0xFF0000FF);
|
cairo_set_source_u32(cairo, 0xFF0000FF);
|
||||||
|
|
||||||
int margin = 3 * output->scale;
|
int margin = 3 * output->scale;
|
||||||
int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
|
int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
|
||||||
|
|
||||||
|
char *font = output->bar->config->font;
|
||||||
int text_width, text_height;
|
int text_width, text_height;
|
||||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
get_text_size(cairo, font, &text_width, &text_height, NULL,
|
||||||
output->scale, false, "%s", error);
|
output->scale, false, "%s", error);
|
||||||
|
|
||||||
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
||||||
uint32_t ideal_surface_height = ideal_height / output->scale;
|
uint32_t ideal_surface_height = ideal_height / output->scale;
|
||||||
if (surface_height < ideal_surface_height) {
|
if (output->height < ideal_surface_height) {
|
||||||
return ideal_surface_height;
|
return ideal_surface_height;
|
||||||
}
|
}
|
||||||
*x -= text_width + margin;
|
*x -= text_width + margin;
|
||||||
|
|
||||||
double text_y = height / 2.0 - text_height / 2.0;
|
double text_y = height / 2.0 - text_height / 2.0;
|
||||||
cairo_move_to(cairo, *x, (int)floor(text_y));
|
cairo_move_to(cairo, *x, (int)floor(text_y));
|
||||||
pango_printf(cairo, config->font, output->scale, false, "%s", error);
|
pango_printf(cairo, font, output->scale, false, "%s", error);
|
||||||
*x -= margin;
|
*x -= margin;
|
||||||
return surface_height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_status_line_text(cairo_t *cairo,
|
static uint32_t render_status_line_text(cairo_t *cairo,
|
||||||
struct swaybar_output *output, struct swaybar_config *config,
|
struct swaybar_output *output, double *x) {
|
||||||
const char *text, bool focused, double *x, uint32_t surface_height) {
|
const char *text = output->bar->status->text;
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t height = surface_height * output->scale;
|
struct swaybar_config *config = output->bar->config;
|
||||||
|
cairo_set_source_u32(cairo, output->focused ?
|
||||||
cairo_set_source_u32(cairo, focused ?
|
|
||||||
config->colors.focused_statusline : config->colors.statusline);
|
config->colors.focused_statusline : config->colors.statusline);
|
||||||
|
|
||||||
int text_width, text_height;
|
int text_width, text_height;
|
||||||
|
@ -72,17 +73,18 @@ static uint32_t render_status_line_text(cairo_t *cairo,
|
||||||
|
|
||||||
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
||||||
uint32_t ideal_surface_height = ideal_height / output->scale;
|
uint32_t ideal_surface_height = ideal_height / output->scale;
|
||||||
if (surface_height < ideal_surface_height) {
|
if (output->height < ideal_surface_height) {
|
||||||
return ideal_surface_height;
|
return ideal_surface_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
*x -= text_width + margin;
|
*x -= text_width + margin;
|
||||||
|
uint32_t height = output->height * output->scale;
|
||||||
double text_y = height / 2.0 - text_height / 2.0;
|
double text_y = height / 2.0 - text_height / 2.0;
|
||||||
cairo_move_to(cairo, *x, (int)floor(text_y));
|
cairo_move_to(cairo, *x, (int)floor(text_y));
|
||||||
pango_printf(cairo, config->font, output->scale,
|
pango_printf(cairo, config->font, output->scale,
|
||||||
config->pango_markup, "%s", text);
|
config->pango_markup, "%s", text);
|
||||||
*x -= margin;
|
*x -= margin;
|
||||||
return surface_height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render_sharp_line(cairo_t *cairo, uint32_t color,
|
static void render_sharp_line(cairo_t *cairo, uint32_t color,
|
||||||
|
@ -122,12 +124,11 @@ static void i3bar_block_unref_callback(void *data) {
|
||||||
|
|
||||||
static uint32_t render_status_block(cairo_t *cairo,
|
static uint32_t render_status_block(cairo_t *cairo,
|
||||||
struct swaybar_output *output, struct i3bar_block *block, double *x,
|
struct swaybar_output *output, struct i3bar_block *block, double *x,
|
||||||
uint32_t surface_height, bool focused, bool edge) {
|
bool edge) {
|
||||||
if (!block->full_text || !*block->full_text) {
|
if (!block->full_text || !*block->full_text) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t height = surface_height * output->scale;
|
|
||||||
struct swaybar_config *config = output->bar->config;
|
struct swaybar_config *config = output->bar->config;
|
||||||
|
|
||||||
int text_width, text_height;
|
int text_width, text_height;
|
||||||
|
@ -145,7 +146,7 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
double block_width = width;
|
double block_width = width;
|
||||||
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
||||||
uint32_t ideal_surface_height = ideal_height / output->scale;
|
uint32_t ideal_surface_height = ideal_height / output->scale;
|
||||||
if (surface_height < ideal_surface_height) {
|
if (output->height < ideal_surface_height) {
|
||||||
return ideal_surface_height;
|
return ideal_surface_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +167,7 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
output->scale, false, "%s", config->sep_symbol);
|
output->scale, false, "%s", config->sep_symbol);
|
||||||
uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
|
uint32_t _ideal_height = sep_height + ws_vertical_padding * 2;
|
||||||
uint32_t _ideal_surface_height = _ideal_height / output->scale;
|
uint32_t _ideal_surface_height = _ideal_height / output->scale;
|
||||||
if (surface_height < _ideal_surface_height) {
|
if (output->height < _ideal_surface_height) {
|
||||||
return _ideal_surface_height;
|
return _ideal_surface_height;
|
||||||
}
|
}
|
||||||
if (sep_width > block->separator_block_width) {
|
if (sep_width > block->separator_block_width) {
|
||||||
|
@ -178,6 +179,7 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
*x -= margin;
|
*x -= margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t height = output->height * output->scale;
|
||||||
if (output->bar->status->click_events) {
|
if (output->bar->status->click_events) {
|
||||||
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
||||||
hotspot->x = *x;
|
hotspot->x = *x;
|
||||||
|
@ -241,7 +243,7 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!edge && block->separator) {
|
if (!edge && block->separator) {
|
||||||
if (focused) {
|
if (output->focused) {
|
||||||
cairo_set_source_u32(cairo, config->colors.focused_separator);
|
cairo_set_source_u32(cairo, config->colors.focused_separator);
|
||||||
} else {
|
} else {
|
||||||
cairo_set_source_u32(cairo, config->colors.separator);
|
cairo_set_source_u32(cairo, config->colors.separator);
|
||||||
|
@ -260,19 +262,16 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
cairo_stroke(cairo);
|
cairo_stroke(cairo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return surface_height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
||||||
struct swaybar_config *config, struct swaybar_output *output,
|
struct swaybar_output *output, double *x) {
|
||||||
struct status_line *status, bool focused,
|
|
||||||
double *x, uint32_t surface_height) {
|
|
||||||
uint32_t max_height = 0;
|
uint32_t max_height = 0;
|
||||||
bool edge = true;
|
bool edge = true;
|
||||||
struct i3bar_block *block;
|
struct i3bar_block *block;
|
||||||
wl_list_for_each(block, &status->blocks, link) {
|
wl_list_for_each(block, &output->bar->status->blocks, link) {
|
||||||
uint32_t h = render_status_block(cairo, output,
|
uint32_t h = render_status_block(cairo, output, block, x, edge);
|
||||||
block, x, surface_height, focused, edge);
|
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
edge = false;
|
edge = false;
|
||||||
}
|
}
|
||||||
|
@ -280,19 +279,15 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_status_line(cairo_t *cairo,
|
static uint32_t render_status_line(cairo_t *cairo,
|
||||||
struct swaybar_config *config, struct swaybar_output *output,
|
struct swaybar_output *output, double *x) {
|
||||||
struct status_line *status, bool focused,
|
struct status_line *status = output->bar->status;
|
||||||
double *x, uint32_t surface_height) {
|
|
||||||
switch (status->protocol) {
|
switch (status->protocol) {
|
||||||
case PROTOCOL_ERROR:
|
case PROTOCOL_ERROR:
|
||||||
return render_status_line_error(cairo, output, config,
|
return render_status_line_error(cairo, output, x);
|
||||||
status->text, x, surface_height);
|
|
||||||
case PROTOCOL_TEXT:
|
case PROTOCOL_TEXT:
|
||||||
return render_status_line_text(cairo, output, config,
|
return render_status_line_text(cairo, output, x);
|
||||||
status->text, focused, x, surface_height);
|
|
||||||
case PROTOCOL_I3BAR:
|
case PROTOCOL_I3BAR:
|
||||||
return render_status_line_i3bar(cairo, config, output,
|
return render_status_line_i3bar(cairo, output, x);
|
||||||
status, focused, x, surface_height);
|
|
||||||
case PROTOCOL_UNDEF:
|
case PROTOCOL_UNDEF:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -300,10 +295,9 @@ static uint32_t render_status_line(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
||||||
struct swaybar_output *output, struct swaybar_config *config,
|
struct swaybar_output *output, double x) {
|
||||||
const char *mode, double x, uint32_t surface_height) {
|
struct swaybar_config *config = output->bar->config;
|
||||||
uint32_t height = surface_height * output->scale;
|
const char *mode = config->mode;
|
||||||
|
|
||||||
int text_width, text_height;
|
int text_width, text_height;
|
||||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
||||||
output->scale, config->mode_pango_markup,
|
output->scale, config->mode_pango_markup,
|
||||||
|
@ -316,11 +310,12 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
||||||
uint32_t ideal_height = text_height + ws_vertical_padding * 2
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2
|
||||||
+ border_width * 2;
|
+ border_width * 2;
|
||||||
uint32_t ideal_surface_height = ideal_height / output->scale;
|
uint32_t ideal_surface_height = ideal_height / output->scale;
|
||||||
if (surface_height < ideal_surface_height) {
|
if (output->height < ideal_surface_height) {
|
||||||
return ideal_surface_height;
|
return ideal_surface_height;
|
||||||
}
|
}
|
||||||
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
|
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
|
||||||
|
|
||||||
|
uint32_t height = output->height * output->scale;
|
||||||
cairo_set_source_u32(cairo, config->colors.binding_mode.background);
|
cairo_set_source_u32(cairo, config->colors.binding_mode.background);
|
||||||
cairo_rectangle(cairo, x, 0, width, height);
|
cairo_rectangle(cairo, x, 0, width, height);
|
||||||
cairo_fill(cairo);
|
cairo_fill(cairo);
|
||||||
|
@ -340,7 +335,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
||||||
cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
|
cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
|
||||||
pango_printf(cairo, config->font, output->scale, config->mode_pango_markup,
|
pango_printf(cairo, config->font, output->scale, config->mode_pango_markup,
|
||||||
"%s", mode);
|
"%s", mode);
|
||||||
return surface_height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *strip_workspace_number(const char *ws_name) {
|
static const char *strip_workspace_number(const char *ws_name) {
|
||||||
|
@ -366,8 +361,9 @@ static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_out
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_workspace_button(cairo_t *cairo,
|
static uint32_t render_workspace_button(cairo_t *cairo,
|
||||||
struct swaybar_output *output, struct swaybar_config *config,
|
struct swaybar_output *output,
|
||||||
struct swaybar_workspace *ws, double *x, uint32_t surface_height) {
|
struct swaybar_workspace *ws, double *x) {
|
||||||
|
struct swaybar_config *config = output->bar->config;
|
||||||
const char *name = ws->name;
|
const char *name = ws->name;
|
||||||
if (config->strip_workspace_numbers) {
|
if (config->strip_workspace_numbers) {
|
||||||
name = strip_workspace_number(ws->name);
|
name = strip_workspace_number(ws->name);
|
||||||
|
@ -384,7 +380,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
||||||
box_colors = config->colors.inactive_workspace;
|
box_colors = config->colors.inactive_workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t height = surface_height * output->scale;
|
uint32_t height = output->height * output->scale;
|
||||||
|
|
||||||
int text_width, text_height;
|
int text_width, text_height;
|
||||||
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
get_text_size(cairo, config->font, &text_width, &text_height, NULL,
|
||||||
|
@ -397,7 +393,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
||||||
uint32_t ideal_height = ws_vertical_padding * 2 + text_height
|
uint32_t ideal_height = ws_vertical_padding * 2 + text_height
|
||||||
+ border_width * 2;
|
+ border_width * 2;
|
||||||
uint32_t ideal_surface_height = ideal_height / output->scale;
|
uint32_t ideal_surface_height = ideal_height / output->scale;
|
||||||
if (surface_height < ideal_surface_height) {
|
if (output->height < ideal_surface_height) {
|
||||||
return ideal_surface_height;
|
return ideal_surface_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,11 +430,11 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
||||||
wl_list_insert(&output->hotspots, &hotspot->link);
|
wl_list_insert(&output->hotspots, &hotspot->link);
|
||||||
|
|
||||||
*x += width;
|
*x += width;
|
||||||
return surface_height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_to_cairo(cairo_t *cairo,
|
static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) {
|
||||||
struct swaybar *bar, struct swaybar_output *output) {
|
struct swaybar *bar = output->bar;
|
||||||
struct swaybar_config *config = bar->config;
|
struct swaybar_config *config = bar->config;
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||||
if (output->focused) {
|
if (output->focused) {
|
||||||
|
@ -458,22 +454,19 @@ static uint32_t render_to_cairo(cairo_t *cairo,
|
||||||
*/
|
*/
|
||||||
double x = output->width * output->scale;
|
double x = output->width * output->scale;
|
||||||
if (bar->status) {
|
if (bar->status) {
|
||||||
uint32_t h = render_status_line(cairo, config, output,
|
uint32_t h = render_status_line(cairo, output, &x);
|
||||||
bar->status, output->focused, &x, output->height);
|
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
}
|
}
|
||||||
x = 0;
|
x = 0;
|
||||||
if (config->workspace_buttons) {
|
if (config->workspace_buttons) {
|
||||||
struct swaybar_workspace *ws;
|
struct swaybar_workspace *ws;
|
||||||
wl_list_for_each_reverse(ws, &output->workspaces, link) {
|
wl_list_for_each_reverse(ws, &output->workspaces, link) {
|
||||||
uint32_t h = render_workspace_button(cairo,
|
uint32_t h = render_workspace_button(cairo, output, ws, &x);
|
||||||
output, config, ws, &x, output->height);
|
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config->binding_mode_indicator && config->mode) {
|
if (config->binding_mode_indicator && config->mode) {
|
||||||
uint32_t h = render_binding_mode_indicator(cairo,
|
uint32_t h = render_binding_mode_indicator(cairo, output, x);
|
||||||
output, config, config->mode, x, output->height);
|
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,9 +499,10 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
||||||
cairo_paint(cairo);
|
cairo_paint(cairo);
|
||||||
cairo_restore(cairo);
|
cairo_restore(cairo);
|
||||||
uint32_t height = render_to_cairo(cairo, bar, output);
|
uint32_t height = render_to_cairo(cairo, output);
|
||||||
if (bar->config->height >= 0 && height < (uint32_t)bar->config->height) {
|
int config_height = output->bar->config->height;
|
||||||
height = bar->config->height;
|
if (config_height >= 0 && height < (uint32_t)config_height) {
|
||||||
|
height = config_height;
|
||||||
}
|
}
|
||||||
if (height != output->height) {
|
if (height != output->height) {
|
||||||
// Reconfigure surface
|
// Reconfigure surface
|
||||||
|
@ -519,7 +513,7 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
||||||
wl_surface_commit(output->surface);
|
wl_surface_commit(output->surface);
|
||||||
} else if (height > 0) {
|
} else if (height > 0) {
|
||||||
// Replay recording into shm and send it off
|
// Replay recording into shm and send it off
|
||||||
output->current_buffer = get_next_buffer(bar->shm,
|
output->current_buffer = get_next_buffer(output->bar->shm,
|
||||||
output->buffers,
|
output->buffers,
|
||||||
output->width * output->scale,
|
output->width * output->scale,
|
||||||
output->height * output->scale);
|
output->height * output->scale);
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "swaybar/bar.h"
|
||||||
#include "swaybar/config.h"
|
#include "swaybar/config.h"
|
||||||
|
#include "swaybar/i3bar.h"
|
||||||
#include "swaybar/event_loop.h"
|
#include "swaybar/event_loop.h"
|
||||||
#include "swaybar/status_line.h"
|
#include "swaybar/status_line.h"
|
||||||
#include "readline.h"
|
#include "readline.h"
|
||||||
|
|
Loading…
Reference in a new issue