summaryrefslogtreecommitdiff
path: root/swaybar
diff options
context:
space:
mode:
authorReza Jelveh <[email protected]>2024-04-15 13:39:41 +0800
committerGitHub <[email protected]>2024-04-15 01:39:41 -0400
commitfb86ed6b0588dfdebfb66ce875bc63cfa0a897f6 (patch)
tree29857a1769107adc58696f08d379f608aa4e29a2 /swaybar
parenta5e79676c4bd22fc5902182acf0667907202a465 (diff)
feat: 1.9 merge (#277)
Co-authored-by: William McKinnon <[email protected]> Co-authored-by: Erik Reider <[email protected]>
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c21
-rw-r--r--swaybar/input.c27
-rw-r--r--swaybar/ipc.c9
-rw-r--r--swaybar/render.c31
-rw-r--r--swaybar/tray/host.c10
-rw-r--r--swaybar/tray/icon.c26
-rw-r--r--swaybar/tray/watcher.c11
7 files changed, 68 insertions, 67 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 5e4ebd97..021fc3bd 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -362,6 +362,9 @@ static void handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
bar->xdg_output_manager = wl_registry_bind(registry, name,
&zxdg_output_manager_v1_interface, 2);
+ } else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
+ bar->cursor_shape_manager = wl_registry_bind(registry, name,
+ &wp_cursor_shape_manager_v1_interface, 1);
}
}
@@ -425,15 +428,17 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
// Second roundtrip for xdg-output
wl_display_roundtrip(bar->display);
- struct swaybar_seat *seat;
- wl_list_for_each(seat, &bar->seats, link) {
- struct swaybar_pointer *pointer = &seat->pointer;
- if (!pointer) {
- continue;
+ if (!bar->cursor_shape_manager) {
+ struct swaybar_seat *seat;
+ wl_list_for_each(seat, &bar->seats, link) {
+ struct swaybar_pointer *pointer = &seat->pointer;
+ if (!pointer) {
+ continue;
+ }
+ pointer->cursor_surface =
+ wl_compositor_create_surface(bar->compositor);
+ assert(pointer->cursor_surface);
}
- pointer->cursor_surface =
- wl_compositor_create_surface(bar->compositor);
- assert(pointer->cursor_surface);
}
if (bar->config->status_command) {
diff --git a/swaybar/input.c b/swaybar/input.c
index 8eccf542..ada4bc86 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -81,8 +81,16 @@ void update_cursor(struct swaybar_seat *seat) {
int scale = pointer->current ? pointer->current->scale : 1;
pointer->cursor_theme = wl_cursor_theme_load(
cursor_theme, cursor_size * scale, seat->bar->shm);
+ if (!pointer->cursor_theme) {
+ sway_log(SWAY_ERROR, "Failed to load cursor theme");
+ return;
+ }
struct wl_cursor *cursor;
- cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
+ cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "default");
+ if (!cursor) {
+ sway_log(SWAY_ERROR, "Failed to get default cursor from theme");
+ return;
+ }
pointer->cursor_image = cursor->images[0];
wl_surface_set_buffer_scale(pointer->cursor_surface, scale);
wl_surface_attach(pointer->cursor_surface,
@@ -103,7 +111,7 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
struct swaybar_pointer *pointer = &seat->pointer;
seat->pointer.x = wl_fixed_to_double(surface_x);
seat->pointer.y = wl_fixed_to_double(surface_y);
- pointer->serial = serial;
+
struct swaybar_output *output;
wl_list_for_each(output, &seat->bar->outputs, link) {
if (output->surface == surface) {
@@ -111,7 +119,18 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
break;
}
}
- update_cursor(seat);
+
+ if (seat->bar->cursor_shape_manager) {
+ struct wp_cursor_shape_device_v1 *device =
+ wp_cursor_shape_manager_v1_get_pointer(
+ seat->bar->cursor_shape_manager, wl_pointer);
+ wp_cursor_shape_device_v1_set_shape(device, serial,
+ WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
+ wp_cursor_shape_device_v1_destroy(device);
+ } else {
+ pointer->serial = serial;
+ update_cursor(seat);
+ }
}
static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
@@ -207,7 +226,7 @@ static void workspace_next(struct swaybar *bar, struct swaybar_output *output,
}
}
- if (new) {
+ if (new && new != active) {
ipc_send_workspace_command(bar, new->name);
// Since we're asking Sway to switch to 'new', it should become visible.
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 9d81a9fb..33ae6544 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -426,12 +426,9 @@ bool ipc_initialize(struct swaybar *bar) {
}
free(res);
- struct swaybar_config *config = bar->config;
- char subscribe[128]; // suitably large buffer
- len = snprintf(subscribe, 128,
- "[ \"barconfig_update\" , \"bar_state_update\" %s %s ]",
- config->binding_mode_indicator ? ", \"mode\"" : "",
- config->workspace_buttons ? ", \"workspace\"" : "");
+ char *subscribe =
+ "[ \"barconfig_update\", \"bar_state_update\", \"mode\", \"workspace\" ]";
+ len = strlen(subscribe);
free(ipc_single_command(bar->ipc_event_socketfd,
IPC_SUBSCRIBE, subscribe, &len));
return true;
diff --git a/swaybar/render.c b/swaybar/render.c
index ccf36563..1113ca44 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -693,15 +693,6 @@ static uint32_t render_to_cairo(struct render_context *ctx) {
struct swaybar_output *output = ctx->output;
struct swaybar *bar = output->bar;
struct swaybar_config *config = bar->config;
- cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
- if (output->focused) {
- ctx->background_color = config->colors.focused_background;
- } else {
- ctx->background_color = config->colors.background;
- }
-
- cairo_set_source_u32(cairo, ctx->background_color);
- cairo_paint(cairo);
int th;
get_text_size(cairo, config->font_description, NULL, &th, NULL, 1, false, "");
@@ -763,8 +754,17 @@ void render_frame(struct swaybar_output *output) {
free_hotspots(&output->hotspots);
+ uint32_t background_color;
+ if (output->focused) {
+ background_color = output->bar->config->colors.focused_background;
+ } else {
+ background_color = output->bar->config->colors.background;
+ }
+
struct render_context ctx = { 0 };
ctx.output = output;
+ // initial background color used for deciding the best way to antialias text
+ ctx.background_color = background_color;
cairo_surface_t *recorder = cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, NULL);
@@ -774,24 +774,23 @@ void render_frame(struct swaybar_output *output) {
ctx.cairo = cairo;
cairo_font_options_t *fo = cairo_font_options_create();
- cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL);
cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_GRAY);
ctx.textaa_safe = fo;
if (output->subpixel == WL_OUTPUT_SUBPIXEL_NONE) {
ctx.textaa_sharp = ctx.textaa_safe;
} else {
fo = cairo_font_options_create();
- cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL);
cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL);
cairo_font_options_set_subpixel_order(fo,
to_cairo_subpixel_order(output->subpixel));
ctx.textaa_sharp = fo;
}
- cairo_save(cairo);
- cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
+
+ cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_u32(cairo, background_color);
cairo_paint(cairo);
- cairo_restore(cairo);
+
uint32_t height = render_to_cairo(&ctx);
int config_height = output->bar->config->height;
if (config_height > 0) {
@@ -836,13 +835,15 @@ void render_frame(struct swaybar_output *output) {
wl_surface_damage(output->surface, 0, 0,
output->width, output->height);
- uint32_t bg_alpha = ctx.background_color & 0xFF;
+ uint32_t bg_alpha = background_color & 0xFF;
if (bg_alpha == 0xFF) {
struct wl_region *region =
wl_compositor_create_region(output->bar->compositor);
wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_set_opaque_region(output->surface, region);
wl_region_destroy(region);
+ } else {
+ wl_surface_set_opaque_region(output->surface, NULL);
}
struct wl_callback *frame_callback = wl_surface_frame(output->surface);
diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c
index ddf2416d..eea2caa5 100644
--- a/swaybar/tray/host.c
+++ b/swaybar/tray/host.c
@@ -10,6 +10,7 @@
#include "swaybar/tray/tray.h"
#include "list.h"
#include "log.h"
+#include "stringop.h"
static const char *watcher_path = "/StatusNotifierWatcher";
@@ -138,12 +139,10 @@ static int handle_new_watcher(sd_bus_message *msg,
bool init_host(struct swaybar_host *host, char *protocol,
struct swaybar_tray *tray) {
- size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1;
- host->watcher_interface = malloc(len);
+ host->watcher_interface = format_str("org.%s.StatusNotifierWatcher", protocol);
if (!host->watcher_interface) {
return false;
}
- snprintf(host->watcher_interface, len, "org.%s.StatusNotifierWatcher", protocol);
sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL, *watcher_slot = NULL;
int ret = sd_bus_match_signal(tray->bus, &reg_slot, host->watcher_interface,
@@ -173,13 +172,10 @@ bool init_host(struct swaybar_host *host, char *protocol,
}
pid_t pid = getpid();
- size_t service_len = snprintf(NULL, 0, "org.%s.StatusNotifierHost-%d",
- protocol, pid) + 1;
- host->service = malloc(service_len);
+ host->service = format_str("org.%s.StatusNotifierHost-%d", protocol, pid);
if (!host->service) {
goto error;
}
- snprintf(host->service, service_len, "org.%s.StatusNotifierHost-%d", protocol, pid);
ret = sd_bus_request_name(tray->bus, host->service, 0);
if (ret < 0) {
sway_log(SWAY_DEBUG, "Failed to acquire service name: %s", strerror(-ret));
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c
index c426c3d4..b513dca5 100644
--- a/swaybar/tray/icon.c
+++ b/swaybar/tray/icon.c
@@ -40,9 +40,7 @@ static list_t *get_basedirs(void) {
data_dirs = strdup(data_dirs);
char *dir = strtok(data_dirs, ":");
do {
- size_t path_len = snprintf(NULL, 0, "%s/icons", dir) + 1;
- char *path = malloc(path_len);
- snprintf(path, path_len, "%s/icons", dir);
+ char *path = format_str("%s/icons", dir);
list_add(basedirs, path);
} while ((dir = strtok(NULL, ":")));
free(data_dirs);
@@ -206,13 +204,7 @@ static const char *entry_handler(char *group, char *key, char *value,
*/
static struct icon_theme *read_theme_file(char *basedir, char *theme_name) {
// look for index.theme file
- size_t path_len = snprintf(NULL, 0, "%s/%s/index.theme", basedir,
- theme_name) + 1;
- char *path = malloc(path_len);
- if (!path) {
- return NULL;
- }
- snprintf(path, path_len, "%s/%s/index.theme", basedir, theme_name);
+ char *path = format_str("%s/%s/index.theme", basedir, theme_name);
FILE *theme_file = fopen(path, "r");
free(path);
if (!theme_file) {
@@ -416,26 +408,20 @@ static char *find_icon_in_subdir(char *name, char *basedir, char *theme,
#endif
};
- size_t path_len = snprintf(NULL, 0, "%s/%s/%s/%s.EXT", basedir, theme,
- subdir, name) + 1;
- char *path = malloc(path_len);
-
for (size_t i = 0; i < sizeof(extensions) / sizeof(*extensions); ++i) {
- snprintf(path, path_len, "%s/%s/%s/%s.%s", basedir, theme, subdir,
- name, extensions[i]);
+ char *path = format_str("%s/%s/%s/%s.%s",
+ basedir, theme, subdir, name, extensions[i]);
if (access(path, R_OK) == 0) {
return path;
}
+ free(path);
}
- free(path);
return NULL;
}
static bool theme_exists_in_basedir(char *theme, char *basedir) {
- size_t path_len = snprintf(NULL, 0, "%s/%s", basedir, theme) + 1;
- char *path = malloc(path_len);
- snprintf(path, path_len, "%s/%s", basedir, theme);
+ char *path = format_str("%s/%s", basedir, theme);
bool ret = dir_exists(path);
free(path);
return ret;
diff --git a/swaybar/tray/watcher.c b/swaybar/tray/watcher.c
index 16afc27c..2458a8c2 100644
--- a/swaybar/tray/watcher.c
+++ b/swaybar/tray/watcher.c
@@ -6,6 +6,7 @@
#include <string.h>
#include "list.h"
#include "log.h"
+#include "stringop.h"
#include "swaybar/tray/watcher.h"
static const char *obj_path = "/StatusNotifierWatcher";
@@ -76,9 +77,7 @@ static int register_sni(sd_bus_message *msg, void *data, sd_bus_error *error) {
service = service_or_path;
path = "/StatusNotifierItem";
}
- size_t id_len = snprintf(NULL, 0, "%s%s", service, path) + 1;
- id = malloc(id_len);
- snprintf(id, id_len, "%s%s", service, path);
+ id = format_str("%s%s", service, path);
}
if (list_seq_find(watcher->items, cmp_id, id) == -1) {
@@ -107,7 +106,7 @@ static int register_host(sd_bus_message *msg, void *data, sd_bus_error *error) {
sway_log(SWAY_DEBUG, "Registering Status Notifier Host '%s'", service);
list_add(watcher->hosts, strdup(service));
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
- "StatusNotifierHostRegistered", "s", service);
+ "StatusNotifierHostRegistered", "");
} else {
sway_log(SWAY_DEBUG, "Status Notifier Host '%s' already registered", service);
}
@@ -159,9 +158,7 @@ struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus) {
return NULL;
}
- size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1;
- watcher->interface = malloc(len);
- snprintf(watcher->interface, len, "org.%s.StatusNotifierWatcher", protocol);
+ watcher->interface = format_str("org.%s.StatusNotifierWatcher", protocol);
sd_bus_slot *signal_slot = NULL, *vtable_slot = NULL;
int ret = sd_bus_add_object_vtable(bus, &vtable_slot, obj_path,