Merge remote-tracking branch 'upstream/master' into master

This commit is contained in:
TheAvidDev 2020-10-11 14:17:06 -04:00
commit 0dc19521ca
15 changed files with 142 additions and 23 deletions

View file

@ -232,6 +232,7 @@ sway_cmd bar_cmd_unbindcode;
sway_cmd bar_cmd_unbindsym;
sway_cmd bar_cmd_wrap_scroll;
sway_cmd bar_cmd_workspace_buttons;
sway_cmd bar_cmd_workspace_min_width;
sway_cmd bar_colors_cmd_active_workspace;
sway_cmd bar_colors_cmd_background;

View file

@ -322,6 +322,7 @@ struct bar_config {
struct side_gaps gaps;
int status_padding;
int status_edge_padding;
uint32_t workspace_min_width;
struct {
char *background;
char *statusline;

View file

@ -162,6 +162,7 @@ struct sway_xwayland_view {
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;
struct wl_listener override_redirect;
};
struct sway_xwayland_unmanaged {
@ -176,6 +177,7 @@ struct sway_xwayland_unmanaged {
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;
struct wl_listener override_redirect;
};
#endif
struct sway_view_child;

View file

@ -38,6 +38,7 @@ struct swaybar_config {
bool binding_mode_indicator;
bool wrap_scroll;
bool workspace_buttons;
uint32_t workspace_min_width;
list_t *bindings;
struct wl_list outputs; // config_output::link
int height;

View file

@ -36,6 +36,7 @@ static struct cmd_handler bar_handlers[] = {
{ "unbindcode", bar_cmd_unbindcode },
{ "unbindsym", bar_cmd_unbindsym },
{ "workspace_buttons", bar_cmd_workspace_buttons },
{ "workspace_min_width", bar_cmd_workspace_min_width },
{ "wrap_scroll", bar_cmd_wrap_scroll },
};

View file

@ -0,0 +1,33 @@
#include <stdlib.h>
#include <strings.h>
#include "config.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "log.h"
struct cmd_results *bar_cmd_workspace_min_width(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "workspace_min_width", EXPECTED_AT_LEAST, 1))) {
return error;
}
struct bar_config *bar = config->current_bar;
char *end;
int min_width = strtol(argv[0], &end, 10);
if (min_width < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) {
return cmd_results_new(CMD_INVALID,
"[Bar %s] Invalid minimum workspace button width value: %s",
bar->id, argv[0]);
}
if (argc == 2 && strcasecmp(argv[1], "px") != 0) {
return cmd_results_new(CMD_INVALID,
"Expected 'workspace_min_width <px> [px]'");
}
sway_log(SWAY_DEBUG, "[Bar %s] Setting minimum workspace button width to %d",
bar->id, min_width);
config->current_bar->workspace_min_width = min_width;
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

@ -105,6 +105,7 @@ struct bar_config *default_bar_config(void) {
bar->modifier = get_modifier_mask_by_name("Mod4");
bar->status_padding = 1;
bar->status_edge_padding = 3;
bar->workspace_min_width = 0;
if (!(bar->mode = strdup("dock"))) {
goto cleanup;
}

View file

@ -118,12 +118,36 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {
static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xwayland_unmanaged *surface =
wl_container_of(listener, surface, destroy);
wl_list_remove(&surface->request_configure.link);
wl_list_remove(&surface->map.link);
wl_list_remove(&surface->unmap.link);
wl_list_remove(&surface->destroy.link);
wl_list_remove(&surface->override_redirect.link);
free(surface);
}
static void handle_map(struct wl_listener *listener, void *data);
struct sway_xwayland_view *create_xwayland_view(struct wlr_xwayland_surface *xsurface);
static void unmanaged_handle_override_redirect(struct wl_listener *listener, void *data) {
struct sway_xwayland_unmanaged *surface =
wl_container_of(listener, surface, override_redirect);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
bool mapped = xsurface->mapped;
if (mapped) {
unmanaged_handle_unmap(&surface->unmap, NULL);
}
unmanaged_handle_destroy(&surface->destroy, NULL);
xsurface->data = NULL;
struct sway_xwayland_view *xwayland_view = create_xwayland_view(xsurface);
if (mapped) {
handle_map(&xwayland_view->map, xsurface);
}
}
static struct sway_xwayland_unmanaged *create_unmanaged(
struct wlr_xwayland_surface *xsurface) {
struct sway_xwayland_unmanaged *surface =
@ -144,6 +168,8 @@ static struct sway_xwayland_unmanaged *create_unmanaged(
surface->unmap.notify = unmanaged_handle_unmap;
wl_signal_add(&xsurface->events.destroy, &surface->destroy);
surface->destroy.notify = unmanaged_handle_destroy;
wl_signal_add(&xsurface->events.set_override_redirect, &surface->override_redirect);
surface->override_redirect.notify = unmanaged_handle_override_redirect;
return surface;
}
@ -418,6 +444,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&xwayland_view->set_decorations.link);
wl_list_remove(&xwayland_view->map.link);
wl_list_remove(&xwayland_view->unmap.link);
wl_list_remove(&xwayland_view->override_redirect.link);
view_begin_destroy(&xwayland_view->view);
}
@ -441,16 +468,6 @@ static void handle_map(struct wl_listener *listener, void *data) {
struct wlr_xwayland_surface *xsurface = data;
struct sway_view *view = &xwayland_view->view;
if (xsurface->override_redirect) {
// This window used not to have the override redirect flag and has it
// now. Switch to unmanaged.
handle_destroy(&xwayland_view->destroy, view);
xsurface->data = NULL;
struct sway_xwayland_unmanaged *unmanaged = create_unmanaged(xsurface);
unmanaged_handle_map(&unmanaged->map, xsurface);
return;
}
view->natural_width = xsurface->width;
view->natural_height = xsurface->height;
@ -465,6 +482,25 @@ static void handle_map(struct wl_listener *listener, void *data) {
transaction_commit_dirty();
}
static void handle_override_redirect(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, override_redirect);
struct wlr_xwayland_surface *xsurface = data;
struct sway_view *view = &xwayland_view->view;
bool mapped = xsurface->mapped;
if (mapped) {
handle_unmap(&xwayland_view->unmap, NULL);
}
handle_destroy(&xwayland_view->destroy, view);
xsurface->data = NULL;
struct sway_xwayland_unmanaged *unmanaged = create_unmanaged(xsurface);
if (mapped) {
unmanaged_handle_map(&unmanaged->map, xsurface);
}
}
static void handle_request_configure(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, request_configure);
@ -637,22 +673,14 @@ struct sway_view *view_from_wlr_xwayland_surface(
return xsurface->data;
}
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
struct wlr_xwayland_surface *xsurface = data;
if (xsurface->override_redirect) {
sway_log(SWAY_DEBUG, "New xwayland unmanaged surface");
create_unmanaged(xsurface);
return;
}
struct sway_xwayland_view *create_xwayland_view(struct wlr_xwayland_surface *xsurface) {
sway_log(SWAY_DEBUG, "New xwayland surface title='%s' class='%s'",
xsurface->title, xsurface->class);
struct sway_xwayland_view *xwayland_view =
calloc(1, sizeof(struct sway_xwayland_view));
if (!sway_assert(xwayland_view, "Failed to allocate view")) {
return;
return NULL;
}
view_init(&xwayland_view->view, SWAY_VIEW_XWAYLAND, &view_impl);
@ -711,7 +739,25 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&xsurface->events.map, &xwayland_view->map);
xwayland_view->map.notify = handle_map;
wl_signal_add(&xsurface->events.set_override_redirect,
&xwayland_view->override_redirect);
xwayland_view->override_redirect.notify = handle_override_redirect;
xsurface->data = xwayland_view;
return xwayland_view;
}
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
struct wlr_xwayland_surface *xsurface = data;
if (xsurface->override_redirect) {
sway_log(SWAY_DEBUG, "New xwayland unmanaged surface");
create_unmanaged(xsurface);
return;
}
create_xwayland_view(xsurface);
}
void handle_xwayland_ready(struct wl_listener *listener, void *data) {

View file

@ -1102,6 +1102,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_new_boolean(bar->strip_workspace_numbers));
json_object_object_add(json, "strip_workspace_name",
json_object_new_boolean(bar->strip_workspace_name));
json_object_object_add(json, "workspace_min_width",
json_object_new_int(bar->workspace_min_width));
json_object_object_add(json, "binding_mode_indicator",
json_object_new_boolean(bar->binding_mode_indicator));
json_object_object_add(json, "verbose",

View file

@ -145,6 +145,7 @@ sway_sources = files(
'commands/bar/tray_output.c',
'commands/bar/tray_padding.c',
'commands/bar/workspace_buttons.c',
'commands/bar/workspace_min_width.c',
'commands/bar/wrap_scroll.c',
'commands/input/accel_profile.c',

View file

@ -138,6 +138,11 @@ runtime.
*workspace_buttons* yes|no
Enables or disables workspace buttons on the bar. Default is _yes_.
*workspace_min_width* <px> [px]
Specifies the minimum width for the workspace buttons on the bar. Default is _0_.
This setting also applies to the current binding mode indicator.
## TRAY
Swaybar provides a system tray where third-party applications may place icons.

View file

@ -829,6 +829,9 @@ their value mean can be found in *sway-bar*(5):
|- workspace_buttons
: boolean
: Whether to display the workspace buttons on the bar
|- workspace_min_width
: integer
: Minimum width in px for the workspace buttons on the bar
|- binding_mode_indicator
: boolean
: Whether to display the current binding mode on the bar
@ -931,6 +934,7 @@ containing the _#RRGGBBAA_ representation of the color:
"status_padding": 1,
"status_edge_padding": 3,
"workspace_buttons": true,
"workspace_min_width": 0,
"binding_mode_indicator": true,
"verbose": false,
"pango_markup": false,

View file

@ -35,6 +35,7 @@ struct swaybar_config *init_config(void) {
config->binding_mode_indicator = true;
config->wrap_scroll = false;
config->workspace_buttons = true;
config->workspace_min_width = 0;
config->bindings = create_list();
wl_list_init(&config->outputs);
config->status_padding = 1;

View file

@ -270,6 +270,12 @@ static bool ipc_parse_config(
config->workspace_buttons = json_object_get_boolean(workspace_buttons);
}
json_object *workspace_min_width =
json_object_object_get(bar_config, "workspace_min_width");
if (workspace_min_width) {
config->workspace_min_width = json_object_get_int(workspace_min_width);
}
json_object *wrap_scroll = json_object_object_get(bar_config, "wrap_scroll");
if (wrap_scroll) {
config->wrap_scroll = json_object_get_boolean(wrap_scroll);

View file

@ -402,7 +402,11 @@ static uint32_t predict_workspace_button_length(cairo_t *cairo,
return 0;
}
return ws_horizontal_padding * 2 + text_width + border_width * 2;
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
return width;
}
static uint32_t predict_workspace_buttons_length(cairo_t *cairo,
@ -446,7 +450,11 @@ static uint32_t predict_binding_mode_indicator_length(cairo_t *cairo,
output->height < ideal_surface_height) {
return 0;
}
return text_width + ws_horizontal_padding * 2 + border_width * 2;
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
return width;
}
static uint32_t render_status_line_i3bar(cairo_t *cairo,
@ -518,6 +526,9 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
return ideal_surface_height;
}
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
uint32_t height = output->height * output->scale;
cairo_set_source_u32(cairo, config->colors.binding_mode.background);
@ -585,7 +596,10 @@ static uint32_t render_workspace_button(cairo_t *cairo,
return ideal_surface_height;
}
uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2;
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
if (width < config->workspace_min_width * output->scale) {
width = config->workspace_min_width * output->scale;
}
cairo_set_source_u32(cairo, box_colors.background);
cairo_rectangle(cairo, *x, 0, width, height);