diff --git a/.gitignore b/.gitignore index 9c5e8bd..638ef1d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ st *.o *.orig *.rej +.ccls-cache diff --git a/x.c b/x.c index 3f6e5b6..caa154f 100644 --- a/x.c +++ b/x.c @@ -886,37 +886,46 @@ xclear(int x1, int y1, int x2, int y2) void xhints(void) { - XClassHint class = {opt_name ? opt_name : "st", - opt_class ? opt_class : "St"}; - XWMHints wm = {.flags = InputHint, .input = 1}; - XSizeHints *sizeh; + XClassHint class = {opt_name ? opt_name : "st", + opt_class ? opt_class : "St-class"}; + XWMHints wm = {.flags = InputHint, .input = 1}; + XSizeHints *sizeh; + XClassHint current_class; + Status status; - sizeh = XAllocSizeHints(); + status = XGetClassHint(xw.dpy, xw.win, ¤t_class); + if (status == True) { + if (strcmp(current_class.res_class, class.res_class) != 0) { + class.res_class = current_class.res_class; /* current_class.res_class; */ + } + } - sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize; - sizeh->height = win.h; - sizeh->width = win.w; - sizeh->height_inc = win.ch; - sizeh->width_inc = win.cw; - sizeh->base_height = 2 * borderpx; - sizeh->base_width = 2 * borderpx; - sizeh->min_height = win.ch + 2 * borderpx; - sizeh->min_width = win.cw + 2 * borderpx; - if (xw.isfixed) { - sizeh->flags |= PMaxSize; - sizeh->min_width = sizeh->max_width = win.w; - sizeh->min_height = sizeh->max_height = win.h; - } - if (xw.gm & (XValue|YValue)) { - sizeh->flags |= USPosition | PWinGravity; - sizeh->x = xw.l; - sizeh->y = xw.t; - sizeh->win_gravity = xgeommasktogravity(xw.gm); - } + sizeh = XAllocSizeHints(); - XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm, - &class); - XFree(sizeh); + sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize; + sizeh->height = win.h; + sizeh->width = win.w; + sizeh->height_inc = win.ch; + sizeh->width_inc = win.cw; + sizeh->base_height = 2 * borderpx; + sizeh->base_width = 2 * borderpx; + sizeh->min_height = win.ch + 2 * borderpx; + sizeh->min_width = win.cw + 2 * borderpx; + if (xw.isfixed) { + sizeh->flags |= PMaxSize; + sizeh->min_width = sizeh->max_width = win.w; + sizeh->min_height = sizeh->max_height = win.h; + } + if (xw.gm & (XValue|YValue)) { + sizeh->flags |= USPosition | PWinGravity; + sizeh->x = xw.l; + sizeh->y = xw.t; + sizeh->win_gravity = xgeommasktogravity(xw.gm); + } + + XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm, + &class); + XFree(sizeh); } int