mirror of
https://github.com/swaywm/sway.git
synced 2026-05-03 06:46:26 -04:00
Fix icon.c and tray/tray.c rendering
This commit is contained in:
parent
a568637a45
commit
339149807f
5 changed files with 70 additions and 52 deletions
|
|
@ -21,8 +21,7 @@ void tray_mouse_event(struct output *output, int x, int y,
|
|||
*/
|
||||
|
||||
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output,
|
||||
struct swaybar_config *config, struct swaybar_workspace *ws,
|
||||
double *pos, uint32_t height);
|
||||
struct swaybar_config *config, double *pos, uint32_t height);
|
||||
|
||||
/**
|
||||
* Initializes the tray with D-Bus
|
||||
|
|
|
|||
|
|
@ -253,6 +253,9 @@ void bar_setup(struct swaybar *bar,
|
|||
const char *socket_path, const char *bar_id) {
|
||||
bar_init(bar);
|
||||
init_event_loop();
|
||||
#ifdef ENABLE_TRAY
|
||||
init_tray(bar);
|
||||
#endif
|
||||
|
||||
bar->ipc_socketfd = ipc_open_socket(socket_path);
|
||||
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
|
||||
|
|
@ -301,9 +304,6 @@ void bar_setup(struct swaybar *bar,
|
|||
}
|
||||
ipc_get_workspaces(bar);
|
||||
render_all_frames(bar);
|
||||
#ifdef ENABLE_TRAY
|
||||
init_tray(bar);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void display_in(int fd, short mask, void *_bar) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@
|
|||
#include "swaybar/ipc.h"
|
||||
#include "swaybar/render.h"
|
||||
#include "swaybar/status_line.h"
|
||||
#ifdef ENABLE_TRAY
|
||||
#include "swaybar/tray/tray.h"
|
||||
#endif
|
||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||
|
||||
static const int ws_horizontal_padding = 5;
|
||||
|
|
@ -410,6 +413,9 @@ static uint32_t render_to_cairo(cairo_t *cairo,
|
|||
max_height = h > max_height ? h : max_height;
|
||||
}
|
||||
x = output->width;
|
||||
#ifdef ENABLE_TRAY
|
||||
render_tray(cairo, output, config, &x, output->height);
|
||||
#endif
|
||||
if (bar->status) {
|
||||
uint32_t h = render_status_line(cairo, config, output, bar->status,
|
||||
output->focused, &x, output->width, output->height);
|
||||
|
|
@ -420,7 +426,7 @@ static uint32_t render_to_cairo(cairo_t *cairo,
|
|||
}
|
||||
|
||||
void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
||||
struct swaybar_hotspot *hotspot, *tmp;
|
||||
struct swaybar_hotspot *hotspot, *tmp;
|
||||
wl_list_for_each_safe(hotspot, tmp, &output->hotspots, link) {
|
||||
if (hotspot->destroy) {
|
||||
hotspot->destroy(hotspot->data);
|
||||
|
|
|
|||
|
|
@ -16,50 +16,6 @@
|
|||
#include "stringop.h"
|
||||
#include "log.h"
|
||||
|
||||
/* Finds all themes that the given theme inherits */
|
||||
static list_t *find_inherits(const char *theme_dir) {
|
||||
const char inherits[] = "Inherits";
|
||||
const char index_name[] = "/index.theme";
|
||||
list_t *themes = create_list();
|
||||
FILE *index = NULL;
|
||||
char *path = malloc(strlen(theme_dir) + sizeof(index_name));
|
||||
if (!path) {
|
||||
goto fail;
|
||||
}
|
||||
if (!themes) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
strcpy(path, theme_dir);
|
||||
strcat(path, index_name);
|
||||
|
||||
index = fopen(path, "r");
|
||||
if (!index) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
char *buf = NULL;
|
||||
size_t n = 0;
|
||||
while (!feof(index) && getline(&buf, &n, index) != -1) {
|
||||
if (n <= sizeof(inherits) + 1) {
|
||||
continue;
|
||||
}
|
||||
if (strncmp(inherits, buf, sizeof(inherits) - 1) == 0) {
|
||||
char *themestr = buf + sizeof(inherits);
|
||||
themes = split_string(themestr, ",");
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
|
||||
fail:
|
||||
free(path);
|
||||
if (index) {
|
||||
fclose(index);
|
||||
}
|
||||
return themes;
|
||||
}
|
||||
|
||||
static bool isdir(const char *path) {
|
||||
struct stat statbuf;
|
||||
if (stat(path, &statbuf) != -1) {
|
||||
|
|
@ -161,6 +117,64 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Finds all themes that the given theme inherits */
|
||||
static list_t *find_inherits(const char *theme_dir) {
|
||||
const char inherits[] = "Inherits";
|
||||
const char index_name[] = "/index.theme";
|
||||
list_t *themes = create_list();
|
||||
FILE *index = NULL;
|
||||
char *path = malloc(strlen(theme_dir) + sizeof(index_name));
|
||||
if (!path) {
|
||||
goto fail;
|
||||
}
|
||||
if (!themes) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
strcpy(path, theme_dir);
|
||||
strcat(path, index_name);
|
||||
|
||||
index = fopen(path, "r");
|
||||
if (!index) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
char *buf = NULL;
|
||||
char *themestr = NULL;
|
||||
size_t n = 0;
|
||||
while (!feof(index) && getline(&buf, &n, index) != -1) {
|
||||
if (n <= sizeof(inherits) + 1) {
|
||||
continue;
|
||||
}
|
||||
if (strncmp(inherits, buf, sizeof(inherits) - 1) == 0) {
|
||||
themestr = buf + sizeof(inherits);
|
||||
int len = strlen(themestr);
|
||||
if (themestr[len-1] == '\n') {
|
||||
themestr[len-1] = '\0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (themestr) {
|
||||
char *token = strtok(themestr, ",");
|
||||
while(token) {
|
||||
char *dir = find_theme_dir(token);
|
||||
if (dir) {
|
||||
list_add(themes,dir);
|
||||
}
|
||||
token = strtok(NULL, ",");
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
|
||||
fail:
|
||||
free(path);
|
||||
if (index) {
|
||||
fclose(index);
|
||||
}
|
||||
return themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all theme dirs needed to be looked in for an icon.
|
||||
* Does not check for duplicates
|
||||
|
|
|
|||
|
|
@ -391,8 +391,7 @@ err:
|
|||
//}
|
||||
|
||||
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output,
|
||||
struct swaybar_config *config, struct swaybar_workspace *ws,
|
||||
double *pos, uint32_t height) {
|
||||
struct swaybar_config *config, double *pos, uint32_t height) {
|
||||
|
||||
double original_width = *pos;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue