all repos — tint2 @ 51211fa6265673668d28a9285daba96cd2748a33

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Systray: new config option systray_name_filter
o9000 mrovi9000@gmail.com
commit

51211fa6265673668d28a9285daba96cd2748a33

parent

1fc417e24ef92de5319fab079a2fa94abf76f489

M doc/tint2.mddoc/tint2.md

@@ -463,6 +463,8 @@ * `systray_icon_asb = alpha (0 to 100) saturation (-100 to 100) brightness (-100 to 100)` : Adjust the systray icons color and transparency.

* `systray_monitor = integer (1, 2, ...)` : On which monitor to draw the systray. The first monitor is `1`. *(since 0.12)* + * `systray_name_filter = string` : Regular expression to identify icon names to be hidden. For example, `^audacious$` will hide icons with the exact name `audacious`, while `aud` will hide any icons having `aud` in the name. *(since 0.14)* + ### Clock * `time1_format = %H:%M` : The format used by the first line of the clock.
M src/config.csrc/config.c

@@ -1009,8 +1009,10 @@ systray.saturation = atoi(value2);

systray.brightness = atoi(value3); } else if (strcmp(key, "systray_monitor") == 0) { systray_monitor = atoi(value) - 1; - } else if (strcmp(key, "systray_hide_by_icon_name") == 0) { - strcpy(systray_hide_icons, value); + } else if (strcmp(key, "systray_name_filter") == 0) { + if (systray_hide_name_filter) + free(systray_hide_name_filter); + systray_hide_name_filter = strdup(value); } /* Launcher */
M src/systray/systraybar.csrc/systray/systraybar.c

@@ -20,6 +20,7 @@

#include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> +#include <regex.h> #include <stdio.h> #include <stdlib.h> #include <string.h>

@@ -54,7 +55,8 @@ int systray_monitor;

int chrono; int systray_composited; int systray_profile; -char systray_hide_icons[100]; +char *systray_hide_name_filter; +regex_t *systray_hide_name_regex; // background pixmap if we render ourselves the icons static Pixmap render_background;

@@ -82,6 +84,8 @@ systray.area._on_change_layout = on_change_systray;

systray.area.size_mode = LAYOUT_FIXED; systray.area._resize = resize_systray; systray_profile = getenv("SYSTRAY_PROFILING") != NULL; + systray_hide_name_filter = NULL; + systray_hide_name_regex = NULL; } void cleanup_systray()

@@ -96,6 +100,12 @@ if (render_background) {

XFreePixmap(server.display, render_background); render_background = 0; } + if (systray_hide_name_regex) { + regfree(systray_hide_name_regex); + free_and_null(systray_hide_name_regex); + } + if (systray_hide_name_filter) + free_and_null(systray_hide_name_filter); } void init_systray()

@@ -574,6 +584,26 @@ }

} } +gboolean reject_icon(Window win) +{ + if (systray_hide_name_filter) { + if (!systray_hide_name_regex) { + systray_hide_name_regex = (regex_t *) calloc(1, sizeof(*systray_hide_name_regex)); + if (regcomp(systray_hide_name_regex, systray_hide_name_filter, 0) != 0) { + fprintf(stderr, RED "Could not compile regex %s" RESET "\n", systray_hide_name_filter); + free_and_null(systray_hide_name_regex); + return FALSE; + } + } + char *name = get_window_name(win); + if (regexec(systray_hide_name_regex, name, 0, NULL, 0) == 0) { + fprintf(stderr, GREEN "Filtering out systray icon '%s'" RESET "\n", name); + return TRUE; + } + } + return FALSE; +} + gboolean add_icon(Window win) { // Avoid duplicates

@@ -584,21 +614,9 @@ return FALSE;

} } - char *name = get_window_name(win); - // Filter out systray_hide_by_icon_name - char *token; - char *string; - string = strdup(systray_hide_icons); - if (string != NULL && string[0] != '0') { - while ((token = strsep(&string, ",")) != NULL) { - if (strcmp(token,name) == 0) { - if (strcmp(token,"") == 0) token = "empty name"; - fprintf(stderr, GREEN "filtering out '%s'\n", token); - return FALSE; - } - } - } + if (reject_icon(win)) + return FALSE; // Dangerous actions begin XSync(server.display, False);

@@ -607,6 +625,7 @@ XErrorHandler old = XSetErrorHandler(window_error_handler);

XSelectInput(server.display, win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask); + char *name = get_window_name(win); if (systray_profile) fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, win, name); Panel *panel = systray.area.panel;
M src/systray/systraybar.hsrc/systray/systraybar.h

@@ -75,7 +75,7 @@ extern gboolean systray_enabled;

extern int systray_max_icon_size; extern int systray_monitor; extern gboolean systray_profile; -extern char systray_hide_icons[100]; +extern char *systray_hide_name_filter; // default global data void default_systray();
M src/tint2conf/properties.csrc/tint2conf/properties.c

@@ -101,7 +101,7 @@

// systray GtkWidget *systray_icon_order, *systray_padding_x, *systray_padding_y, *systray_spacing; GtkWidget *systray_icon_size, *systray_icon_opacity, *systray_icon_saturation, *systray_icon_brightness; -GtkWidget *systray_background, *systray_monitor; +GtkWidget *systray_background, *systray_monitor, *systray_name_filter; // tooltip GtkWidget *tooltip_padding_x, *tooltip_padding_y, *tooltip_font, *tooltip_font_set, *tooltip_font_color;

@@ -4484,6 +4484,19 @@ gtk_widget_show(systray_icon_brightness);

gtk_table_attach(GTK_TABLE(table), systray_icon_brightness, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; gtk_tooltips_set_tip(tooltips, systray_icon_brightness, _("Specifies the brightness adjustment of the system tray icons, in percent."), NULL); + + row++, col = 2; + label = gtk_label_new(_("Name filter")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_widget_show(label); + gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); + col++; + + systray_name_filter = gtk_entry_new(); + gtk_widget_show(systray_name_filter); + gtk_entry_set_width_chars(GTK_ENTRY(systray_name_filter), 50); + gtk_table_attach(GTK_TABLE(table), systray_name_filter, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); + col++; } void create_battery(GtkWidget *parent)
M src/tint2conf/properties.hsrc/tint2conf/properties.h

@@ -111,7 +111,7 @@

// systray extern GtkWidget *systray_icon_order, *systray_padding_x, *systray_padding_y, *systray_spacing; extern GtkWidget *systray_icon_size, *systray_icon_opacity, *systray_icon_saturation, *systray_icon_brightness; -extern GtkWidget *systray_background, *systray_monitor; +extern GtkWidget *systray_background, *systray_monitor, *systray_name_filter; // tooltip extern GtkWidget *tooltip_padding_x, *tooltip_padding_y, *tooltip_font, *tooltip_font_set, *tooltip_font_color;
M src/tint2conf/properties_rw.csrc/tint2conf/properties_rw.c

@@ -622,6 +622,8 @@ fprintf(fp, "systray_monitor = ");

fprintf(fp, "%d", MAX(1, 1 + gtk_combo_box_get_active(GTK_COMBO_BOX(systray_monitor)))); fprintf(fp, "\n"); + fprintf(fp, "systray_name_filter = %s\n", gtk_entry_get_text(GTK_ENTRY(systray_name_filter))); + fprintf(fp, "\n"); }

@@ -1705,6 +1707,8 @@ extract_values(value, &value1, &value2, &value3);

gtk_spin_button_set_value(GTK_SPIN_BUTTON(systray_icon_opacity), atoi(value1)); gtk_spin_button_set_value(GTK_SPIN_BUTTON(systray_icon_saturation), atoi(value2)); gtk_spin_button_set_value(GTK_SPIN_BUTTON(systray_icon_brightness), atoi(value3)); + } else if (strcmp(key, "systray_name_filter") == 0) { + gtk_entry_set_text(GTK_ENTRY(systray_name_filter), value); } /* Launcher */