Compare commits

..

9 Commits

11 changed files with 212 additions and 105 deletions

View File

@@ -11,6 +11,8 @@
- Experimental, testing/feedback needed
- Icons (system tray, task buttons, launcher):
- Changed rendering method to fix icon corruptions (please report any problems)
- System tray:
- Workaround for misbehaving applications leaving empty tray icons
- Many bugfixes
- New config options (see https://gitlab.com/o9000/tint2/wikis/Configure):
- Panel:

View File

@@ -1,14 +1,14 @@
### New unstable release: 0.12-rc3
### New unstable release: 0.12-rc4
Changes: https://gitlab.com/o9000/tint2/blob/master/ChangeLog
Documentation: https://gitlab.com/o9000/tint2/wikis/home
Try it out with (see also [dependencies](https://gitlab.com/o9000/tint2/wikis/Install#dependencies)):
```
mkdir tint2-0.12-rc3
cd tint2-0.12-rc3
wget 'https://gitlab.com/o9000/tint2/repository/archive.tar.gz?ref=v0.12-rc3' --output-document tint2-0.12-rc3.tar.gz
tar -xzf tint2-0.12-rc3.tar.gz
mkdir tint2-0.12-rc4
cd tint2-0.12-rc4
wget 'https://gitlab.com/o9000/tint2/repository/archive.tar.gz?ref=v0.12-rc4' --output-document tint2-0.12-rc4.tar.gz
tar -xzf tint2-0.12-rc4.tar.gz
cd tint2.git
mkdir build
cd build
@@ -49,7 +49,7 @@ tint2 is a simple panel/taskbar made for modern X window managers. It was specif
* [Configure](https://gitlab.com/o9000/tint2/wikis/Configure)
* [Add applet not supported by tint2](https://gitlab.com/o9000/tint2/wikis/ThirdPartyApplets)
* [Other frequently asked questions](https://gitlab.com/o9000/tint2/wikis/FAQ)
* [Debug](https://gitlab.com/o9000/tint2/wikis/Debug)
* [Debug](https://gitlab.com/o9000/tint2/wikis/Debug)
### How can I help out?

View File

@@ -76,6 +76,9 @@ void update_battery_tick(void* arg)
int16_t old_hours = battery_state.time.hours;
int8_t old_minutes = battery_state.time.minutes;
if (!battery_found) {
init_battery();
}
if (update_battery() != 0) {
// Reconfigure
init_battery();
@@ -103,15 +106,23 @@ void update_battery_tick(void* arg)
int i;
for (i = 0; i < nb_panel; i++) {
if (!battery_found && panel1[i].battery.area.on_screen == 1) {
hide(&panel1[i].battery.area);
panel_refresh = 1;
} else if (battery_state.percentage >= percentage_hide && panel1[i].battery.area.on_screen == 1) {
hide(&panel1[i].battery.area);
panel_refresh = 1;
} else if (battery_state.percentage < percentage_hide && panel1[i].battery.area.on_screen == 0) {
show(&panel1[i].battery.area);
panel_refresh = 1;
if (!battery_found) {
if (panel1[i].battery.area.on_screen == 1) {
hide(&panel1[i].battery.area);
panel_refresh = 1;
}
} else {
if (battery_state.percentage >= percentage_hide) {
if (panel1[i].battery.area.on_screen == 1) {
hide(&panel1[i].battery.area);
panel_refresh = 1;
}
} else {
if (panel1[i].battery.area.on_screen == 0) {
show(&panel1[i].battery.area);
panel_refresh = 1;
}
}
}
if (panel1[i].battery.area.on_screen == 1) {
panel1[i].battery.area.resize = 1;
@@ -279,7 +290,7 @@ void init_battery()
#endif
if (!battery_timeout)
battery_timeout = add_timeout(10, 10000, update_battery_tick, 0, &battery_timeout);
battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout);
}
@@ -474,7 +485,7 @@ int update_battery() {
battery_state.time.seconds = seconds;
if (energy_full > 0)
new_percentage = ((energy_now <= energy_full ? energy_now : energy_full) * 100) / energy_full;
new_percentage = 0.5 + ((energy_now <= energy_full ? energy_now : energy_full) * 100.0) / energy_full;
battery_state.percentage = new_percentage;

View File

@@ -613,13 +613,13 @@ void add_entry (char *key, char *value)
}
else if (strcmp(key, "systray_sort") == 0) {
if (strcmp(value, "descending") == 0)
systray.sort = -1;
systray.sort = SYSTRAY_SORT_DESCENDING;
else if (strcmp(value, "ascending") == 0)
systray.sort = 1;
systray.sort = SYSTRAY_SORT_ASCENDING;
else if (strcmp(value, "left2right") == 0)
systray.sort = 2;
systray.sort = SYSTRAY_SORT_LEFT2RIGHT;
else if (strcmp(value, "right2left") == 0)
systray.sort = 3;
systray.sort = SYSTRAY_SORT_RIGHT2LEFT;
}
else if (strcmp(key, "systray_icon_size") == 0) {
systray_max_icon_size = atoi(value);

View File

@@ -536,6 +536,9 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
char *next_larger = NULL;
GSList *next_larger_theme = NULL;
int file_name_size = 4096;
char *file_name = calloc(file_name_size, 1);
for (theme = themes; theme; theme = g_slist_next(theme)) {
((IconTheme*)theme->data)->list_directories = g_slist_sort_with_data(((IconTheme*)theme->data)->list_directories,
compare_theme_directories,
@@ -560,8 +563,13 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
char *theme_name = ((IconTheme*)theme->data)->name;
char *dir_name = ((IconThemeDir*)dir->data)->name;
char *extension = (char*) ext->data;
char *file_name = calloc(strlen(base_name) + strlen(theme_name) +
strlen(dir_name) + strlen(icon_name) + strlen(extension) + 100, 1);
if (strlen(base_name) + strlen(theme_name) +
strlen(dir_name) + strlen(icon_name) + strlen(extension) + 100 > file_name_size) {
file_name_size = strlen(base_name) + strlen(theme_name) +
strlen(dir_name) + strlen(icon_name) + strlen(extension) + 100;
file_name = realloc(file_name, file_name_size);
}
file_name[0] = 0;
// filename = directory/$(themename)/subdirectory/iconname.extension
sprintf(file_name, "%s/%s/%s/%s%s", base_name, theme_name, dir_name, icon_name, extension);
if (DEBUG_ICON_SEARCH)
@@ -596,11 +604,12 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
printf("next_larger = %s; next_larger_size = %d\n", next_larger, next_larger_size);
}
}
free(file_name);
}
}
}
}
free(file_name);
file_name = NULL;
if (next_larger) {
g_slist_free(extensions);
free(best_file_name);

View File

@@ -31,6 +31,8 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <sys/types.h>
#include <sys/wait.h>
#ifdef HAVE_RSVG
#include <librsvg/rsvg.h>
@@ -150,8 +152,7 @@ void cleanup_launcher_theme(Launcher *launcher)
for (l = launcher->list_icons; l ; l = l->next) {
LauncherIcon *launcherIcon = (LauncherIcon*)l->data;
if (launcherIcon) {
free_icon(launcherIcon->icon_scaled);
free_icon(launcherIcon->icon_original);
free_icon(launcherIcon->image);
free(launcherIcon->icon_name);
free(launcherIcon->icon_path);
free(launcherIcon->cmd);
@@ -186,7 +187,7 @@ int resize_launcher(void *obj)
// Resize icons if necessary
for (l = launcher->list_icons; l ; l = l->next) {
LauncherIcon *launcherIcon = (LauncherIcon *)l->data;
if (launcherIcon->icon_size != icon_size || !launcherIcon->icon_original) {
if (launcherIcon->icon_size != icon_size || !launcherIcon->image) {
launcherIcon->icon_size = icon_size;
launcherIcon->area.width = launcherIcon->icon_size;
launcherIcon->area.height = launcherIcon->icon_size;
@@ -195,69 +196,69 @@ int resize_launcher(void *obj)
char *new_icon_path = get_icon_path(launcher->list_themes, launcherIcon->icon_name, launcherIcon->icon_size);
if (!new_icon_path) {
// Draw a blank icon
free_icon(launcherIcon->icon_original);
launcherIcon->icon_original = NULL;
free_icon(launcherIcon->icon_scaled);
launcherIcon->icon_scaled = NULL;
free_icon(launcherIcon->image);
launcherIcon->image = NULL;
continue;
}
if (launcherIcon->icon_path && strcmp(new_icon_path, launcherIcon->icon_path) == 0) {
// If it's the same file just rescale
free_icon(launcherIcon->icon_scaled);
launcherIcon->icon_scaled = scale_icon(launcherIcon->icon_original, icon_size);
free(new_icon_path);
fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
} else {
// Free the old files
free_icon(launcherIcon->icon_original);
free_icon(launcherIcon->icon_scaled);
launcherIcon->icon_original = launcherIcon->icon_scaled = NULL;
// Load the new file and scale
launcherIcon->icon_original = imlib_load_image_immediately(new_icon_path);
// Free the old files
free_icon(launcherIcon->image);
launcherIcon->image = NULL;
// Load the new file and scale
launcherIcon->image = imlib_load_image_immediately(new_icon_path);
#ifdef HAVE_RSVG
if (!launcherIcon->icon_original && g_str_has_suffix(new_icon_path, ".svg")) {
if (!launcherIcon->image && g_str_has_suffix(new_icon_path, ".svg")) {
char suffix[128];
sprintf(suffix, "tmpicon-%d.png", getpid());
// We fork here because librsvg allocates memory like crazy
pid_t pid = fork();
if (pid == 0) {
// Child
GError* err = NULL;
RsvgHandle* svg = rsvg_handle_new_from_file(new_icon_path, &err);
if (err != NULL) {
fprintf(stderr, "Could not load svg image!: %s", err->message);
g_error_free(err);
launcherIcon->icon_original = NULL;
launcherIcon->image = NULL;
} else {
char suffix[128];
sprintf(suffix, "tmpicon-%d.png", getpid());
gchar *name = g_build_filename(g_get_user_config_dir(), "tint2", suffix, NULL);
GdkPixbuf *pixbuf = rsvg_handle_get_pixbuf(svg);
gdk_pixbuf_save(pixbuf, name, "png", NULL, NULL);
launcherIcon->icon_original = imlib_load_image_immediately_without_cache(name);
g_remove(name);
g_free(name);
g_object_unref(G_OBJECT(pixbuf));
g_object_unref(G_OBJECT(svg));
}
} else
#endif
{
launcherIcon->icon_original = imlib_load_image_immediately(new_icon_path);
}
// On loading error, fallback to default
if (!launcherIcon->icon_original) {
free(new_icon_path);
new_icon_path = get_icon_path(launcher->list_themes, DEFAULT_ICON, launcherIcon->icon_size);
if (new_icon_path)
launcherIcon->icon_original = imlib_load_image_immediately(new_icon_path);
}
if (!launcherIcon->icon_original) {
// Loading default icon failed, draw a blank icon
free(new_icon_path);
exit(0);
} else {
// Loaded icon successfully
launcherIcon->icon_scaled = scale_icon(launcherIcon->icon_original, launcherIcon->icon_size);
free(launcherIcon->icon_path);
launcherIcon->icon_path = new_icon_path;
fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
// Parent
waitpid(pid, 0, 0);
gchar *name = g_build_filename(g_get_user_config_dir(), "tint2", suffix, NULL);
launcherIcon->image = imlib_load_image_immediately_without_cache(name);
g_remove(name);
g_free(name);
}
} else
#endif
{
launcherIcon->image = imlib_load_image_immediately(new_icon_path);
}
// On loading error, fallback to default
if (!launcherIcon->image) {
free(new_icon_path);
new_icon_path = get_icon_path(launcher->list_themes, DEFAULT_ICON, launcherIcon->icon_size);
if (new_icon_path)
launcherIcon->image = imlib_load_image_immediately(new_icon_path);
}
if (!launcherIcon->image) {
// Loading default icon failed, draw a blank icon
free(new_icon_path);
} else {
// Loaded icon successfully
Imlib_Image original = launcherIcon->image;
launcherIcon->image = scale_icon(launcherIcon->image, launcherIcon->icon_size);
free_icon(original);
free(launcherIcon->icon_path);
launcherIcon->icon_path = new_icon_path;
fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
}
}
}
@@ -331,6 +332,7 @@ int resize_launcher(void *obj)
}
}
}
return 1;
}
@@ -355,9 +357,8 @@ void draw_launcher_icon(void *obj, cairo_t *c)
{
LauncherIcon *launcherIcon = (LauncherIcon*)obj;
Imlib_Image icon_scaled = launcherIcon->icon_scaled;
// Render
imlib_context_set_image(icon_scaled);
imlib_context_set_image(launcherIcon->image);
if (server.real_transparency) {
render_image(launcherIcon->area.pix, 0, 0);
} else {

View File

@@ -23,8 +23,7 @@ typedef struct Launcher {
typedef struct LauncherIcon {
// always start with area
Area area;
Imlib_Image icon_scaled;
Imlib_Image icon_original;
Imlib_Image image;
char *cmd;
char *icon_name;
char *icon_path;

View File

@@ -98,6 +98,7 @@ void server_init_atoms ()
server.atom._NET_SYSTEM_TRAY_ORIENTATION = XInternAtom(server.dsp, "_NET_SYSTEM_TRAY_ORIENTATION", False);
server.atom._XEMBED = XInternAtom(server.dsp, "_XEMBED", False);
server.atom._XEMBED_INFO = XInternAtom(server.dsp, "_XEMBED_INFO", False);
server.atom._NET_WM_PID = XInternAtom(server.dsp, "_NET_WM_PID", True);
// drag 'n' drop
server.atom.XdndAware = XInternAtom(server.dsp, "XdndAware", False);

View File

@@ -74,6 +74,7 @@ typedef struct Global_atom
Atom _NET_SYSTEM_TRAY_ORIENTATION;
Atom _XEMBED;
Atom _XEMBED_INFO;
Atom _NET_WM_PID;
Atom _XSETTINGS_SCREEN;
Atom _XSETTINGS_SETTINGS;
Atom XdndAware;

View File

@@ -52,7 +52,7 @@ int refresh_systray;
int systray_enabled;
int systray_max_icon_size;
int systray_monitor;
int chrono;
// background pixmap if we render ourselves the icons
static Pixmap render_background;
@@ -61,8 +61,9 @@ void default_systray()
{
memset(&systray, 0, sizeof(Systraybar));
render_background = 0;
chrono = 0;
systray.alpha = 100;
systray.sort = 3;
systray.sort = SYSTRAY_SORT_LEFT2RIGHT;
systray.area._draw_foreground = draw_systray;
systray.area._on_change_layout = on_change_systray;
systray.area.size_mode = SIZE_BY_CONTENT;
@@ -108,8 +109,9 @@ void init_systray_panel(void *p)
GSList *l;
int count = 0;
for (l = systray.list_icons; l ; l = l->next) {
if (!((TrayWindow*)l->data)->hide)
count++;
if (((TrayWindow*)l->data)->hide)
continue;
count++;
}
if (count == 0)
hide(&systray.area);
@@ -146,8 +148,9 @@ int resize_systray(void *obj)
sysbar->icon_size = systray_max_icon_size;
count = 0;
for (l = systray.list_icons; l ; l = l->next) {
if (!((TrayWindow*)l->data)->hide)
count++;
if (((TrayWindow*)l->data)->hide)
continue;
count++;
}
//printf("count %d\n", count);
@@ -194,11 +197,12 @@ void on_change_systray (void *obj)
GSList *l;
for (i=1, l = systray.list_icons; l ; i++, l = l->next) {
traywin = (TrayWindow*)l->data;
if (traywin->hide) continue;
if (traywin->hide)
continue;
traywin->y = posy;
traywin->x = posx;
//printf("systray %d : %d,%d\n", i, posx, posy);
// printf("systray %d : pos %d, %d\n", traywin->tray_id, posx, posy);
traywin->width = sysbar->icon_size;
traywin->height = sysbar->icon_size;
if (panel_horizontal) {
@@ -336,21 +340,39 @@ static gint compare_traywindows(gconstpointer a, gconstpointer b)
{
const TrayWindow * traywin_a = (TrayWindow*)a;
const TrayWindow * traywin_b = (TrayWindow*)b;
XTextProperty name_a, name_b;
if(XGetWMName(server.dsp, traywin_a->tray_id, &name_a) == 0) {
return -1;
}
else if(XGetWMName(server.dsp, traywin_b->tray_id, &name_b) == 0) {
XFree(name_a.value);
if (traywin_a->empty && !traywin_b->empty)
return 1;
if (!traywin_a->empty && traywin_b->empty)
return -1;
if (systray.sort == SYSTRAY_SORT_ASCENDING ||
systray.sort == SYSTRAY_SORT_DESCENDING) {
XTextProperty name_a, name_b;
if (XGetWMName(server.dsp, traywin_a->tray_id, &name_a) == 0) {
return -1;
}
else if (XGetWMName(server.dsp, traywin_b->tray_id, &name_b) == 0) {
XFree(name_a.value);
return 1;
}
else {
gint retval = g_ascii_strncasecmp((char*)name_a.value, (char*)name_b.value, -1) *
(systray.sort == SYSTRAY_SORT_ASCENDING ? 1 : -1);
XFree(name_a.value);
XFree(name_b.value);
return retval;
}
}
else {
gint retval = g_ascii_strncasecmp((char*)name_a.value, (char*)name_b.value, -1) * systray.sort;
XFree(name_a.value);
XFree(name_b.value);
return retval;
if (systray.sort == SYSTRAY_SORT_LEFT2RIGHT ||
systray.sort == SYSTRAY_SORT_RIGHT2LEFT) {
return (traywin_a->chrono - traywin_b->chrono) *
(systray.sort == SYSTRAY_SORT_LEFT2RIGHT ? 1 : -1);
}
return 0;
}
@@ -361,12 +383,42 @@ gboolean add_icon(Window id)
Panel *panel = systray.area.panel;
int hide = 0;
int pid = 0;
{
Atom actual_type;
int actual_format;
unsigned long nitems;
unsigned long bytes_after;
unsigned char *prop = 0;
int ret = XGetWindowProperty(server.dsp, id, server.atom._NET_WM_PID, 0, 1024, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop);
if (ret == Success && prop) {
pid = prop[1] * 256;
pid += prop[0];
}
}
GSList *l;
int num_empty_same_pid = 0;
for (l = systray.list_icons; l; l = l->next) {
if (((TrayWindow*)l->data)->tray_id == id)
return FALSE;
if (pid && ((TrayWindow*)l->data)->pid == pid && ((TrayWindow*)l->data)->empty)
num_empty_same_pid++;
}
const int max_num_empty_same_pid = 0;
if (num_empty_same_pid > max_num_empty_same_pid) {
for (l = systray.list_icons; l; l = l->next) {
if (pid && ((TrayWindow*)l->data)->pid == pid && ((TrayWindow*)l->data)->empty) {
num_empty_same_pid++;
fprintf(stderr, "Removing tray icon %lu from misbehaving application with pid=%d\n", ((TrayWindow*)l->data)->tray_id, pid);
remove_icon((TrayWindow*)l->data);
break;
}
}
}
//printf("add_icon: %d, pid %d, %d\n", id, pid, num_empty_same_pid);
error = FALSE;
XWindowAttributes attr;
if ( XGetWindowAttributes(server.dsp, id, &attr) == False ) return FALSE;
@@ -445,16 +497,19 @@ gboolean add_icon(Window id)
traywin->hide = hide;
traywin->depth = attr.depth;
traywin->damage = 0;
traywin->empty = 0;
traywin->pid = pid;
traywin->chrono = chrono;
chrono++;
if (systray.area.on_screen == 0)
show(&systray.area);
if (systray.sort == 3)
if (systray.sort == SYSTRAY_SORT_RIGHT2LEFT)
systray.list_icons = g_slist_prepend(systray.list_icons, traywin);
else if (systray.sort == 2)
systray.list_icons = g_slist_append(systray.list_icons, traywin);
else
systray.list_icons = g_slist_insert_sorted(systray.list_icons, traywin, compare_traywindows);
systray.list_icons = g_slist_append(systray.list_icons, traywin);
systray.list_icons = g_slist_sort(systray.list_icons, compare_traywindows);
//printf("add_icon id %lx, %d\n", id, g_slist_length(systray.list_icons));
if (FORCE_COMPOSITED_RENDERING || server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
@@ -481,7 +536,7 @@ void remove_icon(TrayWindow *traywin)
// remove from our list
systray.list_icons = g_slist_remove(systray.list_icons, traywin);
//printf("remove_icon id %lx, %d\n", traywin->id);
//printf("remove_icon: %d\n", traywin->tray_id);
XSelectInput(server.dsp, traywin->tray_id, NoEventMask);
if (traywin->damage)
@@ -503,8 +558,9 @@ void remove_icon(TrayWindow *traywin)
int count = 0;
GSList *l;
for (l = systray.list_icons; l; l = l->next) {
if (!((TrayWindow*)l->data)->hide)
count++;
if (((TrayWindow*)l->data)->hide)
continue;
count++;
}
if (count == 0)
hide(&systray.area);
@@ -546,6 +602,7 @@ void systray_render_icon_now(void* t)
// we end up in this function only in real transparency mode or if systray_task_asb != 100 0 0
// we made also sure, that we always have a 32 bit visual, i.e. we can safely create 32 bit pixmaps here
TrayWindow* traywin = t;
traywin->render_timeout = 0;
if ( traywin->width == 0 || traywin->height == 0 ) {
// reschedule rendering since the geometry information has not yet been processed (can happen on slow cpu)
@@ -553,6 +610,27 @@ void systray_render_icon_now(void* t)
return;
}
XImage *ximage = XGetImage(server.dsp, traywin->tray_id, 0, 0, traywin->width, traywin->height, AllPlanes, XYPixmap);
XColor color;
int x, y, empty = 1;
for (x = 0; empty && x < traywin->width; x++) {
for (y = 0; empty && y < traywin->height; y++) {
color.pixel = XGetPixel(ximage, x, y);
if (color.pixel != 0)
empty = 0;
}
}
XFree(ximage);
if (traywin->empty != empty) {
traywin->empty = empty;
systray.area.resize = 1;
panel_refresh = 1;
systray.list_icons = g_slist_sort(systray.list_icons, compare_traywindows);
}
//printf("systray_render_icon_now: %d empty %d\n", traywin->tray_id, empty);
if (empty)
return;
// good systray icons support 32 bit depth, but some icons are still 24 bit.
// We create a heuristic mask for these icons, i.e. we get the rgb value in the top left corner, and
// mask out all pixel with the same rgb value
@@ -636,7 +714,8 @@ void refresh_systray_icon()
GSList *l;
for (l = systray.list_icons; l ; l = l->next) {
traywin = (TrayWindow*)l->data;
if (traywin->hide) continue;
if (traywin->hide)
continue;
systray_render_icon(traywin);
}
}

View File

@@ -20,6 +20,7 @@
// Flags for _XEMBED_INFO
#define XEMBED_MAPPED (1 << 0)
enum { SYSTRAY_SORT_ASCENDING, SYSTRAY_SORT_DESCENDING, SYSTRAY_SORT_LEFT2RIGHT, SYSTRAY_SORT_RIGHT2LEFT };
typedef struct {
// always start with area
@@ -43,6 +44,9 @@ typedef struct
int depth;
Damage damage;
timeout* render_timeout;
int empty;
int pid;
int chrono;
} TrayWindow;