diff --git a/manager.c b/manager.c index 808c75a38d371fe495c3dfb6b2147eb1280a5ad4..58ee90ab6ea5761d1fa62ceb4f0f8bd7bc353785 100644 --- a/manager.c +++ b/manager.c @@ -421,6 +421,7 @@ void deinit_window_manager(void) { deinit_audio(); XftColorFree(wm.dpy, DefaultVisual(wm.dpy, wm.screen), wm.cmap, &wm.xft_color); XftColorFree(wm.dpy, DefaultVisual(wm.dpy, wm.screen), wm.cmap, &wm.xft_bg_color); + XftColorFree(wm.dpy, DefaultVisual(wm.dpy, wm.screen), wm.cmap, &wm.xft_root_bg_color); XftColorFree(wm.dpy, DefaultVisual(wm.dpy, wm.screen), wm.cmap, &wm.xft_mic_active_bg); XftColorFree(wm.dpy, DefaultVisual(wm.dpy, wm.screen), wm.cmap, &wm.xft_mic_muted_bg); XftColorFree(wm.dpy, DefaultVisual(wm.dpy, wm.screen), wm.cmap, &wm.xft_mic_active_fg); diff --git a/switcher.c b/switcher.c index e14554aed0dd407597876daa770580ef56f3b858..949bcef08e4b45418f4a211e1b5faa5a77b32f06 100644 --- a/switcher.c +++ b/switcher.c @@ -3,9 +3,9 @@ #include #include #include +#include #include "glitch.h" -#include "config.h" extern WindowManager wm; @@ -27,7 +27,6 @@ int is_selected = (i == wm.active_cycle_index); // Draw box background if (is_selected) { - // Use blue color for active background (wm.xft_bg_color is usually blue from config) XSetForeground(wm.dpy, DefaultGC(wm.dpy, wm.screen), wm.xft_bg_color.pixel); XFillRectangle(wm.dpy, wm.cycle_win, DefaultGC(wm.dpy, wm.screen), x_offset, y_offset, box_size, box_size); } else { @@ -35,30 +34,47 @@ XSetForeground(wm.dpy, DefaultGC(wm.dpy, wm.screen), WhitePixel(wm.dpy, wm.screen)); XFillRectangle(wm.dpy, wm.cycle_win, DefaultGC(wm.dpy, wm.screen), x_offset, y_offset, box_size, box_size); } - // Draw Window Name - char *name = NULL; - Atom utf8_string = XInternAtom(wm.dpy, "UTF8_STRING", False); - if (XFetchName(wm.dpy, w, &name) || XGetWindowProperty(wm.dpy, w, XInternAtom(wm.dpy, "_NET_WM_NAME", False), 0, (~0L), False, utf8_string, &(Atom){0}, &(int){0}, &(unsigned long){0}, &(unsigned long){0}, (unsigned char **)&name) == Success) { - if (name) { - // Selected: White text. Unselected: Black text. - XftColor *color = is_selected ? &wm.xft_color : &wm.xft_root_bg_color; - // NOTE: wm.xft_color is "white" (indicator_fg_color), wm.xft_root_bg_color is "black". + // Get Program Name + char *prog_name = NULL; + XClassHint ch; + if (XGetClassHint(wm.dpy, w, &ch)) { + prog_name = ch.res_class; + if (prog_name) { + char *dash = strchr(prog_name, '-'); + if (dash) *dash = '\0'; + } + if (ch.res_name) XFree(ch.res_name); + } - XftDraw *draw = XftDrawCreate(wm.dpy, wm.cycle_win, DefaultVisual(wm.dpy, wm.screen), wm.cmap); - if (draw) { - if (strlen(name) > 8) { - char truncated[9]; - strncpy(truncated, name, 8); - truncated[8] = '\0'; - XftDrawStringUtf8(draw, color, wm.font, x_offset + 10, y_offset + 90, (const FcChar8 *)truncated, strlen(truncated)); - } else { - XftDrawStringUtf8(draw, color, wm.font, x_offset + 10, y_offset + 90, (const FcChar8 *)name, strlen(name)); - } - XftDrawDestroy(draw); - } - XFree(name); + // Get Window Title + char *win_title = NULL; + if (!XFetchName(wm.dpy, w, &win_title)) { + Atom utf8_string = XInternAtom(wm.dpy, "UTF8_STRING", False); + XGetWindowProperty(wm.dpy, w, XInternAtom(wm.dpy, "_NET_WM_NAME", False), 0, (~0L), False, utf8_string, &(Atom){0}, &(int){0}, &(unsigned long){0}, &(unsigned long){0}, (unsigned char **)&win_title); + } + + XftDraw *draw = XftDrawCreate(wm.dpy, wm.cycle_win, DefaultVisual(wm.dpy, wm.screen), wm.cmap); + if (draw) { + XftColor *color = is_selected ? &wm.xft_color : &wm.xft_root_bg_color; + + if (prog_name) { + char truncated[9]; + strncpy(truncated, prog_name, 8); + truncated[8] = '\0'; + XftDrawStringUtf8(draw, color, wm.font, x_offset + 10, y_offset + 70, (const FcChar8 *)truncated, strlen(truncated)); + } + + if (win_title) { + char truncated[9]; + strncpy(truncated, win_title, 8); + truncated[8] = '\0'; + XftDrawStringUtf8(draw, color, wm.font, x_offset + 10, y_offset + 90, (const FcChar8 *)truncated, strlen(truncated)); } + XftDrawDestroy(draw); } + + if (prog_name) XFree(prog_name); + if (win_title) XFree(win_title); x_offset += box_size; }