Skip to content

Commit

Permalink
xside: add modifiers for "tint" trayicon mode
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarek committed Jun 7, 2016
1 parent 8429457 commit ef27c65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
11 changes: 9 additions & 2 deletions gui-daemon/trayicon.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ void init_tray_tint(Ghandles *g) {
}
rgb_to_hls((color.red >> 8) << 16 | (color.green >> 8) << 8 | (color.blue >> 8),
&g->tint_h, &l_ignore, &g->tint_s);

if (g->trayicon_tint_reduce_saturation)
g->tint_s *= 0.5;
}

void tint_tray_and_update(Ghandles *g, struct windowdata *vm_window,
Expand Down Expand Up @@ -259,8 +262,12 @@ void tint_tray_and_update(Ghandles *g, struct windowdata *vm_window,
for (yp = 0; yp < h; yp++) {
for (xp = 0; xp < w; xp++) {
pixel = XGetPixel(image, xp, yp);
rgb_to_hls(pixel, &h_ignore, &l, &s_ignore);
pixel = hls_to_rgb(g->tint_h, l, g->tint_s);
if (g->trayicon_tint_whitehack && pixel == 0xffffff)
pixel = 0xfefefe;
else {
rgb_to_hls(pixel, &h_ignore, &l, &s_ignore);
pixel = hls_to_rgb(g->tint_h, l, g->tint_s);
}
if (!XPutPixel(image, xp, yp, pixel)) {
fprintf(stderr, "Failed to update pixel %d,%d of tray window 0x%lx(remote 0x%lx)\n",
xp, yp, vm_window->local_winid, vm_window->remote_winid);
Expand Down
17 changes: 15 additions & 2 deletions gui-daemon/xside.c
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,10 @@ static void usage(FILE *stream)
fprintf(stream, " \tbg: color full icon background to the VM color\n");
fprintf(stream, " \tborder1: add 1px border at the icon edges\n");
fprintf(stream, " \tborder2: add 1px border, 1px from the icon edges\n");
fprintf(stream, " \ttint: tint icon to the VM color\n");
fprintf(stream, " \ttint: tint icon to the VM color, can be used with additional modifiers (you can enable multiple of them):\n");
fprintf(stream, " \ttint+border1, tint+border2: same as tint, but also add a border\n");
fprintf(stream, " \ttint+saturation50: same as tint, but reduce icon saturation by 50%%\n");
fprintf(stream, " \ttint+whitehack: same as tint, but change white pixels (0xffffff) to almost-white (0xfefefe)\n");
fprintf(stream, " --help, -h\tPrint help message\n");
fprintf(stream, "\n");
fprintf(stream, "Log levels:\n");
Expand Down Expand Up @@ -2762,9 +2765,17 @@ static void parse_trayicon_mode(Ghandles *g, const char *mode_str) {
} else if (strcmp(mode_str, "border2") == 0) {
g->trayicon_mode = TRAY_BORDER;
g->trayicon_border = 2;
} else if (strcmp(mode_str, "tint") == 0) {
} else if (strncmp(mode_str, "tint", 4) == 0) {
g->trayicon_mode = TRAY_TINT;
g->trayicon_border = 0;
if (strstr(mode_str, "+border1"))
g->trayicon_border = 1;
if (strstr(mode_str, "+border2"))
g->trayicon_border = 2;
if (strstr(mode_str, "+saturation50"))
g->trayicon_tint_reduce_saturation = 1;
if (strstr(mode_str, "+whitehack"))
g->trayicon_tint_whitehack = 1;
} else {
fprintf(stderr, "Invalid trayicon mode: %s\n", mode_str);
exit(1);
Expand Down Expand Up @@ -2884,6 +2895,8 @@ static void load_default_config_values(Ghandles * g)
g->audio_low_latency = 1;
g->trayicon_mode = TRAY_BORDER;
g->trayicon_border = 1;
g->trayicon_tint_reduce_saturation = 0;
g->trayicon_tint_whitehack = 0;
}

// parse string describing key sequence like Ctrl-Alt-c
Expand Down
2 changes: 2 additions & 0 deletions gui-daemon/xside.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ struct _global_handles {
int prefix_titles; /* prefix windows titles with VM name (for WM without support for _QUBES_VMNAME property) */
enum trayicon_mode trayicon_mode; /* trayicon coloring mode */
int trayicon_border; /* position of trayicon border - 0 - no border, 1 - at the edges, 2 - 1px from the edges */
bool trayicon_tint_reduce_saturation; /* reduce trayicon saturation by 50% (available only for "tint" mode) */
bool trayicon_tint_whitehack; /* replace white pixels with almost-white 0xfefefe (available only for "tint" mode) */
};

typedef struct _global_handles Ghandles;
Expand Down

0 comments on commit ef27c65

Please sign in to comment.