diff --git a/doc/alttab.1 b/doc/alttab.1 index 77b554b..deb3f28 100644 --- a/doc/alttab.1 +++ b/doc/alttab.1 @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "ALTTAB" "1" "July 2023" "" +.TH "ALTTAB" "1" "May 2024" "" .SH "NAME" \fBalttab\fR \- the task switcher .SH "SYNOPSIS" @@ -179,7 +179,7 @@ resource: alttab\.icon\.source .br default: 2 .IP -Source of icons\. \fINUMBER\fR must be between 0 and 4: +Source of icons\. \fINUMBER\fR must be between 0 and 5: .IP \fI0\fR: Use icons from X11 window attributes only\. .IP @@ -208,6 +208,8 @@ Also, alttab scans for icons in legacy directories without freedesktop directory \fI3\fR: Use icons from files only\. .IP \fI4\fR: Don't draw icons\. +.IP +\fI5\fR: Prefer icon from X11 window attributes when it matches requested size better\. .TP \fB\-theme\fR \fIname\fR resource: alttab\.theme diff --git a/doc/alttab.1.ronn b/doc/alttab.1.ronn index 5c5f707..c4034c8 100644 --- a/doc/alttab.1.ronn +++ b/doc/alttab.1.ronn @@ -218,7 +218,7 @@ Most command line options have corresponding X resource, see doc/alttab.ad for e resource: alttab.icon.source default: 2 - Source of icons. must be between 0 and 4: + Source of icons. must be between 0 and 5: <0>: Use icons from X11 window attributes only. @@ -249,6 +249,8 @@ Most command line options have corresponding X resource, see doc/alttab.ad for e <4>: Don't draw icons. + <5>: Prefer icon from X11 window attributes when it matches requested size better. + * `-theme` : resource: alttab.theme default: diff --git a/src/alttab.h b/src/alttab.h index b57916d..7864364 100644 --- a/src/alttab.h +++ b/src/alttab.h @@ -187,7 +187,8 @@ typedef struct { #define ISRC_SIZE 2 #define ISRC_FILES 3 #define ISRC_NONE 4 -#define ISRC_MAX 4 +#define ISRC_SIZE2 5 +#define ISRC_MAX 5 #define ISRC_DEFAULT ISRC_SIZE int option_iconSrc; char *option_theme; diff --git a/src/icon.c b/src/icon.c index 3889a8e..6b03be1 100644 --- a/src/icon.c +++ b/src/icon.c @@ -412,7 +412,7 @@ int inspectIconMeta(FTSENT * pe) // new candidate: ix, iy // best value: g.option_iconW, H // should we replace the icon? - if (iconMatchBetter(ix, iy, ic->src_w, ic->src_h)) { + if (iconMatchBetter(ix, iy, ic->src_w, ic->src_h, false)) { strncpy(ic->src_path, pe->fts_path, MAXICONPATHLEN-1); ic->src_w = ix; ic->src_h = iy; @@ -506,13 +506,16 @@ icon_t *lookupIcon(char *app) // // check if new width/height better match icon size option // assuming square icons +// if equal_prefer_new=true and sizes are equal, then prefer new icon // -bool iconMatchBetter(int new_w, int new_h, int old_w, int old_h) +bool iconMatchBetter(int new_w, int new_h, int old_w, int old_h, bool equal_prefer_new) { int hasdiff, newdiff; hasdiff = old_h - g.option_iconH; newdiff = new_h - g.option_iconH; + if (hasdiff == newdiff && equal_prefer_new) + return true; return (hasdiff >= 0) ? ((newdiff < 0) ? false : ((newdiff < hasdiff) ? true : false) diff --git a/src/icon.h b/src/icon.h index b7b2b08..98e13e5 100644 --- a/src/icon.h +++ b/src/icon.h @@ -68,7 +68,7 @@ int loadIconContentPNG(icon_t * ic); int loadIconContentXPM(icon_t * ic); int loadIconContent(icon_t * ic); // update drawable icon_t *lookupIcon(char *app); // search app icon in hash -bool iconMatchBetter(int new_w, int new_h, int old_w, int old_h); +bool iconMatchBetter(int new_w, int new_h, int old_w, int old_h, bool equal_prefer_new); void deleteIconHash(icon_t **ihash); #endif diff --git a/src/win.c b/src/win.c index 5d1965e..f6409ae 100644 --- a/src/win.c +++ b/src/win.c @@ -224,7 +224,7 @@ int addIconFromProperty(WindowInfo * wi) n += w*h; continue; } - if (best == 0 || iconMatchBetter(w, h, best_w, best_h)) { + if (best == 0 || iconMatchBetter(w, h, best_w, best_h, false)) { best = n; } n += w*h; @@ -343,11 +343,20 @@ int addIconFromFiles(WindowInfo * wi) s = tryclass; while ((s = strchr(s, '/')) != NULL) *s++ = '_'; ic = lookupIcon(tryclass); - if (ic && - (g.option_iconSrc != ISRC_SIZE - || iconMatchBetter(ic->src_w, ic->src_h, - wi->icon_w, wi->icon_h)) - ) { + if (ic && ( + (g.option_iconSrc != ISRC_SIZE + && g.option_iconSrc != ISRC_SIZE2) + || (g.option_iconSrc == ISRC_SIZE + && iconMatchBetter( + ic->src_w, ic->src_h, + wi->icon_w, wi->icon_h, + false)) + || (g.option_iconSrc == ISRC_SIZE2 + && iconMatchBetter( + ic->src_w, ic->src_h, + wi->icon_w, wi->icon_h, + true)) + )) { msg(0, "using file icon for %s\n", tryclass); if (ic->drawable == None) { msg(1, "loading content for %s\n", ic->app); @@ -446,7 +455,7 @@ int addWindowInfo(Window win, int reclevel, int wm_id, unsigned long desktop, icon_in_x = addIconFromHints(&(WI)); } if ((opt == ISRC_FALLBACK && !icon_in_x) || - opt == ISRC_SIZE || opt == ISRC_FILES) + opt == ISRC_SIZE || opt == ISRC_SIZE2 || opt == ISRC_FILES) addIconFromFiles(&(WI)); // extract icon width/height/depth