Systray: new config option systray_name_filter
This commit is contained in:
parent
1fc417e24e
commit
51211fa626
7 changed files with 60 additions and 20 deletions
|
@ -463,6 +463,8 @@ The action semantics:
|
||||||
|
|
||||||
* `systray_monitor = integer (1, 2, ...)` : On which monitor to draw the systray. The first monitor is `1`. *(since 0.12)*
|
* `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
|
### Clock
|
||||||
|
|
||||||
* `time1_format = %H:%M` : The format used by the first line of the clock.
|
* `time1_format = %H:%M` : The format used by the first line of the clock.
|
||||||
|
|
|
@ -1009,8 +1009,10 @@ void add_entry(char *key, char *value)
|
||||||
systray.brightness = atoi(value3);
|
systray.brightness = atoi(value3);
|
||||||
} else if (strcmp(key, "systray_monitor") == 0) {
|
} else if (strcmp(key, "systray_monitor") == 0) {
|
||||||
systray_monitor = atoi(value) - 1;
|
systray_monitor = atoi(value) - 1;
|
||||||
} else if (strcmp(key, "systray_hide_by_icon_name") == 0) {
|
} else if (strcmp(key, "systray_name_filter") == 0) {
|
||||||
strcpy(systray_hide_icons, value);
|
if (systray_hide_name_filter)
|
||||||
|
free(systray_hide_name_filter);
|
||||||
|
systray_hide_name_filter = strdup(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Launcher */
|
/* Launcher */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
#include <regex.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -54,7 +55,8 @@ int systray_monitor;
|
||||||
int chrono;
|
int chrono;
|
||||||
int systray_composited;
|
int systray_composited;
|
||||||
int systray_profile;
|
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
|
// background pixmap if we render ourselves the icons
|
||||||
static Pixmap render_background;
|
static Pixmap render_background;
|
||||||
|
|
||||||
|
@ -82,6 +84,8 @@ void default_systray()
|
||||||
systray.area.size_mode = LAYOUT_FIXED;
|
systray.area.size_mode = LAYOUT_FIXED;
|
||||||
systray.area._resize = resize_systray;
|
systray.area._resize = resize_systray;
|
||||||
systray_profile = getenv("SYSTRAY_PROFILING") != NULL;
|
systray_profile = getenv("SYSTRAY_PROFILING") != NULL;
|
||||||
|
systray_hide_name_filter = NULL;
|
||||||
|
systray_hide_name_regex = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup_systray()
|
void cleanup_systray()
|
||||||
|
@ -96,6 +100,12 @@ void cleanup_systray()
|
||||||
XFreePixmap(server.display, render_background);
|
XFreePixmap(server.display, render_background);
|
||||||
render_background = 0;
|
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()
|
void init_systray()
|
||||||
|
@ -574,6 +584,26 @@ void print_icons()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
gboolean add_icon(Window win)
|
||||||
{
|
{
|
||||||
// Avoid duplicates
|
// Avoid duplicates
|
||||||
|
@ -584,21 +614,9 @@ gboolean add_icon(Window win)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *name = get_window_name(win);
|
|
||||||
|
|
||||||
// Filter out systray_hide_by_icon_name
|
// Filter out systray_hide_by_icon_name
|
||||||
char *token;
|
if (reject_icon(win))
|
||||||
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;
|
return FALSE;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dangerous actions begin
|
// Dangerous actions begin
|
||||||
XSync(server.display, False);
|
XSync(server.display, False);
|
||||||
|
@ -607,6 +625,7 @@ gboolean add_icon(Window win)
|
||||||
|
|
||||||
XSelectInput(server.display, win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
|
XSelectInput(server.display, win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
|
||||||
|
|
||||||
|
char *name = get_window_name(win);
|
||||||
if (systray_profile)
|
if (systray_profile)
|
||||||
fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, win, name);
|
fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, win, name);
|
||||||
Panel *panel = systray.area.panel;
|
Panel *panel = systray.area.panel;
|
||||||
|
|
|
@ -75,7 +75,7 @@ extern gboolean systray_enabled;
|
||||||
extern int systray_max_icon_size;
|
extern int systray_max_icon_size;
|
||||||
extern int systray_monitor;
|
extern int systray_monitor;
|
||||||
extern gboolean systray_profile;
|
extern gboolean systray_profile;
|
||||||
extern char systray_hide_icons[100];
|
extern char *systray_hide_name_filter;
|
||||||
|
|
||||||
// default global data
|
// default global data
|
||||||
void default_systray();
|
void default_systray();
|
||||||
|
|
|
@ -101,7 +101,7 @@ GtkWidget *ac_connected_cmd, *ac_disconnected_cmd;
|
||||||
// systray
|
// systray
|
||||||
GtkWidget *systray_icon_order, *systray_padding_x, *systray_padding_y, *systray_spacing;
|
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_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
|
// tooltip
|
||||||
GtkWidget *tooltip_padding_x, *tooltip_padding_y, *tooltip_font, *tooltip_font_set, *tooltip_font_color;
|
GtkWidget *tooltip_padding_x, *tooltip_padding_y, *tooltip_font, *tooltip_font_set, *tooltip_font_color;
|
||||||
|
@ -4484,6 +4484,19 @@ void create_systemtray(GtkWidget *parent)
|
||||||
gtk_table_attach(GTK_TABLE(table), systray_icon_brightness, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
|
gtk_table_attach(GTK_TABLE(table), systray_icon_brightness, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
|
||||||
col++;
|
col++;
|
||||||
gtk_tooltips_set_tip(tooltips, systray_icon_brightness, _("Specifies the brightness adjustment of the system tray icons, in percent."), NULL);
|
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)
|
void create_battery(GtkWidget *parent)
|
||||||
|
|
|
@ -111,7 +111,7 @@ extern GtkWidget *ac_connected_cmd, *ac_disconnected_cmd;
|
||||||
// systray
|
// systray
|
||||||
extern GtkWidget *systray_icon_order, *systray_padding_x, *systray_padding_y, *systray_spacing;
|
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_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
|
// tooltip
|
||||||
extern GtkWidget *tooltip_padding_x, *tooltip_padding_y, *tooltip_font, *tooltip_font_set, *tooltip_font_color;
|
extern GtkWidget *tooltip_padding_x, *tooltip_padding_y, *tooltip_font, *tooltip_font_set, *tooltip_font_color;
|
||||||
|
|
|
@ -622,6 +622,8 @@ void config_write_systray(FILE *fp)
|
||||||
fprintf(fp, "%d", MAX(1, 1 + gtk_combo_box_get_active(GTK_COMBO_BOX(systray_monitor))));
|
fprintf(fp, "%d", MAX(1, 1 + gtk_combo_box_get_active(GTK_COMBO_BOX(systray_monitor))));
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
|
|
||||||
|
fprintf(fp, "systray_name_filter = %s\n", gtk_entry_get_text(GTK_ENTRY(systray_name_filter)));
|
||||||
|
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1705,6 +1707,8 @@ void add_entry(char *key, char *value)
|
||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(systray_icon_opacity), atoi(value1));
|
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_saturation), atoi(value2));
|
||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(systray_icon_brightness), atoi(value3));
|
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 */
|
/* Launcher */
|
||||||
|
|
Loading…
Reference in a new issue