bakkeby / dmenu-flexipatch

A dmenu build with preprocessor directives to decide which patches to include during build time
MIT License
183 stars 78 forks source link

Can I change the sb color when there is nothing piped into dmenu? #9

Closed fov95 closed 2 years ago

fov95 commented 2 years ago

When piping echo into dmenu with borderpatch the selbackground of this empty field has the same color as border color, or better said it's the other way around. as I find the empty selection field pretty annoying with this color and would rather have it the same color0 as the rest there, when there is nothing to be selected. changing sb color sadly also changes the background color of the border... Is there any quickfix for that maybe or would this be too much work to separete selbackground and bordercolor?

bakkeby commented 2 years ago

The border patch is relatively simple with few lines of code changed. The border is defined here using SchemeSel background as the colour of choice.

https://github.com/bakkeby/dmenu-flexipatch/blob/ea2fd892dbc90e5f7657a77a1e2eba027544a79b/dmenu.c#L1686-L1687

If you wanted to you could change this to, say, SchemeBorder, then add SchemeBorder to the list of enums, maybe right after SchemeOut,

https://github.com/bakkeby/dmenu-flexipatch/blob/ea2fd892dbc90e5f7657a77a1e2eba027544a79b/dmenu.c#L58-L81

then you would also want to add that new colour scheme to the colors array in your config.h:

https://github.com/bakkeby/dmenu-flexipatch/blob/ea2fd892dbc90e5f7657a77a1e2eba027544a79b/config.def.h#L64-L87

Example diff for reference:

diff --git a/config.def.h b/config.def.h
index d4db7c3..17b9b09 100644
--- a/config.def.h
+++ b/config.def.h
@@ -66,6 +66,9 @@ char *colors[][2] = {
        [SchemeNorm] = { "#bbbbbb", "#222222" },
        [SchemeSel]  = { "#eeeeee", "#005577" },
        [SchemeOut]  = { "#000000", "#00ffff" },
+       #if BORDER_PATCH
+       [SchemeBorder] = { "#000000", "#005577" },
+       #endif // BORDER_PATCH
        #if MORECOLOR_PATCH
        [SchemeMid]  = { "#eeeeee", "#770000" },
        #endif // MORECOLOR_PATCH
diff --git a/dmenu.c b/dmenu.c
index 2f0c881..241b276 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -59,6 +59,9 @@ enum {
        SchemeNorm,
        SchemeSel,
        SchemeOut,
+       #if BORDER_PATCH
+       SchemeBorder,
+       #endif // BORDER_PATCH
        #if MORECOLOR_PATCH
        SchemeMid,
        #endif // MORECOLOR_PATCH
@@ -1684,7 +1687,7 @@ setup(void)
        );
        #if BORDER_PATCH
        if (border_width)
-               XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel);
+               XSetWindowBorder(dpy, win, scheme[SchemeBorder][ColBg].pixel);
        #endif // BORDER_PATCH
        XSetClassHint(dpy, win, &ch);
        #if WMTYPE_PATCH

That's all there is to it when it comes to adding a new colour scheme. If you are using Xresources then you may want to add code in patch/xresources.c to read resources for this new scheme.

Personally I'd prefer to control the colour of the border separately this way, but I am not entirely sure if it is right to include it in this project as the behaviour would be different than if you were to apply the border patch on a bare 5.0 dmenu.

fov95 commented 2 years ago

Thanks! Okay but now there is something off with the border transparency of dmenu? border and selbg have the exact same color but the border seems to be like 99.95 opaque? Or is there something else weird going on? I was just thinking of the dwm transparency border issue but I wouldn't know.. btw I think the border patch on the suckless side should include a different color for the border.. because selection ≠ border. s

Edit: nvm, it is actually the compositors fault.. xD I don't know why picom thinks 1. all this are different parts and 2. doesn't even apply the set options to it but something random..

fov95 commented 2 years ago

Why is there no color prompt option when "plain prompt" patch is applied like it shows here in the reference from your patches file? https://tools.suckless.org/dmenu/patches/listfullwidth/ I rewrote a little to also have my prompt in a different color because the prompt also uses the selbg color..

fov95 commented 2 years ago

Okay so.. I tried hard to get this right.. In dmenu.c it states if ! PLAIN_PROMPT so that explains why it would not accept my color when the patch was applied.. I had to disable the patch.. But now the text is black.. -.- Man it's hard to get anything done when u have absolutely no clue...

bakkeby commented 2 years ago

Okay but now there is something off with the border transparency of dmenu?

Mmm, dmenu doesn't actually use more than the foreground and background colours so the transparency would be the same as for the main window.

If you use the alpha patch then you could explicitly say that the SchemeBorder should be opaque, e.g.

static const unsigned int alphas[][3]      = {
    /*               fg      bg        border     */
    ...
    #if BORDER_PATCH
    [SchemeBorder] = { OPAQUE, OPAQUE, OPAQUE },
    #endif // BORDER_PATCH
    ...

In general the patches for dmenu or slock are not as polished I have found.

fov95 commented 2 years ago

Yea I already edited the first post like 2 minutes after creating it because I found out it's the compositors fault

fov95 commented 2 years ago

Maybe u could help me out here a bit I'm really trying my best here.. I added

if (XrmGetResource(xdb, "dmenu.prompt", "*", &type, &xval))
colors[SchemePrompt][ColBg] = strdup(xval.addr);
else
colors[SchemePrompt][ColBg] = strdup(colors[SchemePrompt][ColBg]);

to xresources. I would assume this just says, when there is an entry in Xresources that matches dmenu.prompt, use the value from that, if there is no match, use what's in the config. So far so good. In dmenu.c I added

    if (prompt && *prompt) {
        // #if !PLAIN_PROMPT_PATCH
+       if (colorprompt)
+       drw_setscheme(drw, scheme[SchemePrompt]);
        // #endif // PLAIN_PROMPT_PATCH
        x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0
            #if PANGO_PATCH
            , True
            #endif // PANGO_PATCH
        );
    }

Just to give me the option in config, who cares whatever. I commented out the prompt thing to have it either way.

in config [SchemePrompt] = { "#000000", "#00ffff" }, Plus the option... so I am not 100% retarded.. Now the selbg I just change with the -sb flag, terrific and prompt I can also change with xresources, which leaves me with this:

ss

I mean I don't know what I expected.. I only set the BG color I thought. Why did it also change the FG color? I'd like it to stay the way it was.. I mean I honestly don't understand how I would ad another option to also change the fg color of SchemePrompt.. I mean I can only choose one color anyway for any single option in Xresources.... What black magic is going on here?

bakkeby commented 2 years ago

OK, so you have this in your config.h:

char *colors[][2] = {
    /*               fg         bg       */
    [SchemeNorm] = { "#bbbbbb", "#222222" },
    [SchemeSel]  = { "#eeeeee", "#005577" },
    ...
    [SchemePrompt] = { "#000000", "#00ffff" },
    ...
};

A colour scheme defines a foreground (fg) and a background (bg) colour, with #000000 being completely black and #FFFFFF being completely white. I see github shows a coloured circle for RGB colours :)

Similarly in dwm each colour scheme define a foreground (fg), a background (bg) and a border colour.

The Xresources code in dmenu is ugly as hell. I'd probably do it differently if I had a personal build of dmenu. I'd assume that all the else statements are redundant so not sure if they are there for some obscure reason.

If you look closely there are two lookups per colour scheme, one for the foreground and one for the background, e.g. both of these are for the SchemeSel colour scheme:

        if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval))
            colors[SchemeSel][ColBg] = strdup(xval.addr);
        else
            colors[SchemeSel][ColBg] = strdup(colors[SchemeSel][ColBg]);
        if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval))
            colors[SchemeSel][ColFg] = strdup(xval.addr);
        else
            colors[SchemeSel][ColFg] = strdup(colors[SchemeSel][ColFg]);

If you want to add a new scheme here like your SchemePrompt then you would have something like this:

        if (XrmGetResource(xdb, "dmenu.promptbackground", "*", &type, &xval))
            colors[SchemePrompt][ColBg] = strdup(xval.addr);
        else
            colors[SchemePrompt][ColBg] = strdup(colors[SchemePrompt][ColBg]);
        if (XrmGetResource(xdb, "dmenu.promptforeground", "*", &type, &xval))
            colors[SchemePrompt][ColFg] = strdup(xval.addr);
        else
            colors[SchemePrompt][ColFg] = strdup(colors[SchemePrompt][ColFg]);

The black magic you are referring to is just that if there is no X resource string for the foreground colour in this case then it will just use whatever is defined in the colors array in your config.h, which is black for the font.

fov95 commented 2 years ago

Oh right.. must've been too tired to see that -.- thanks a lot