Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Survey of scrollbar colors in Motif #9933

Closed
qsmodo opened this issue Mar 11, 2022 · 7 comments
Closed

Survey of scrollbar colors in Motif #9933

qsmodo opened this issue Mar 11, 2022 · 7 comments

Comments

@qsmodo
Copy link
Contributor

qsmodo commented Mar 11, 2022

Steps to reproduce

xrdb /dev/null
gvim -u NONE -xrm 'Vim.scrollForeground: red'
gvim -u NONE -xrm 'Vim.scrollForeground: red' -xrm 'Vim.scrollBackground: blue'

2022-03-11-173731_355x375_scrot

Expected behaviour

As per :h gui-resources,

    scrollBackground	Color of trough portion of scrollbars.
    scrollForeground	Color of slider and arrow portions of scrollbars.

So the slider and arrow should be red in both cases.

The root of the problem

Is Motif's style of giving things a 3D (?) look with fancy borders and shades. By default, sliderVisual (see XmScrollBar) takes

XmSHADOWED_BACKGROUND

Specifies that the slider visual is in the background color, with a shadow. This is the default for a regular slider.

So, you might think, the solution is simple, just use XmFOREGROUND_COLOR instead, which yields

/usr/local/bin/gvim -u NONE -xrm 'Vim.background:black' -xrm 'Vim.scrollForeground: red' -xrm 'Vim.scrollBackground: black'

Might look good enough, but if you look closely, the area of the trough is of a darker blue, and things get ugly in a dark background:

/usr/local/bin/gvim -xrm 'Vim.scrollForeground: red' -xrm 'Vim.scrollBackground: black'

One way to decrease the ugliness a bit this is by suppressing shadows by passing -xrm 'Vim*scrollBar.shadowThickness: 0':

/usr/local/bin/gvim -xrm 'Vim.scrollForeground: red' -xrm 'Vim.scrollBackground: black' -xrm 'Vim*scrollBar.shadowThickness: 0'

Too bad, the trough is somewhat gray (not the mention the scroll arrows that became almost invisible; but I don't really like them and use the Vim*showArrows: NONE X-resource to make them disappear).

This all you caused by

vim/src/gui_motif.c

Lines 1897 to 1903 in fb43cfc

#if (XmVersion>=1002)
XmChangeColor(sb->id, gui.scroll_bg_pixel);
#else
XtVaSetValues(sb->id,
XmNtroughColor, gui.scroll_bg_pixel,
NULL);
#endif

XmChangeColor handles all color modifications for the specified widget when a new background pixel value is specified. The function recalculates the foreground, select, and shadow colors based on the new background color and sets the corresponding resources for the widget.

So, the natural question is: What if we always go with XtVaSetValues (which is not deprecated)? Then we have this picture below, with the top window being the new default look of Gvim, and beneath it we have gvim -xrm 'Vim.scrollForeground: red' -xrm 'Vim.scrollBackground: black' -xrm 'Vim*scrollBar.shadowThickness: 0', with a dark colorscheme.

2022-03-11-181828_358x376_scrot

The simplest solution is to take away scrollForeground from Motif, but as we've seen the result is very ugly for dark themes. If we don't, then we either have to take away the Motif look from the scrollbar (by using XmFOREGROUND_COLOR and removing XmChangeColor, entirely removing its shadows, giving a sane default foreground color, etc.):

/usr/local/bin/gvim -u NONE -xrm 'VimscrollBar.shadowThickness: 0' -xrm 'VimscrollForeground: gray50'

or let dark theme users live with its ugliness. Unless someone can envisage a simpler solution.

By the way, this is a reason I prefer Athena with its no frills interface. The scrollbar is easily and completely customizable by the end user via X-resources.

Version of Vim

8.2.4318

Environment

OS: Gentoo
Motif: 2.3.8

Logs and stack traces

No response

@brammool
Copy link
Contributor

It looks like I can make it work by also setting the XmNbackground:

	if (gui.scroll_fg_pixel != INVALCOLOR)
	    XtVaSetValues(sb->id,
		    XmNforeground, gui.scroll_fg_pixel,
//#if (XmVersion<1002)
		    XmNbackground, gui.scroll_fg_pixel,
//#endif
		    NULL);

At least then the color of the thumb is red.

@brammool
Copy link
Contributor

I haven't tried it, but perhaps it is also possible to both call XmChangeColor() and then call XtVaSetValues() to set the XmNtroughColor as well? Not sure if that would make any difference.

@qsmodo
Copy link
Contributor Author

qsmodo commented Mar 12, 2022

It looks like I can make it work by also setting the XmNbackground:

	if (gui.scroll_fg_pixel != INVALCOLOR)
	    XtVaSetValues(sb->id,
		    XmNforeground, gui.scroll_fg_pixel,
//#if (XmVersion<1002)
		    XmNbackground, gui.scroll_fg_pixel,
//#endif
		    NULL);

At least then the color of the thumb is red.

True, but we also need to

both call XmChangeColor() and then call XtVaSetValues() to set the XmNtroughColor as well

otherwise the through won't honor the background color (it will get slightly altered, such as that dark grey look instead of black in one of the pictures above).

Also, the initialization of the scrollbar colors is lacking gui_get_color, so it currently doesn't pull color definitions from the X server database. As such, we need

-       gui.menu_fg_pixel = gui.menu_def_fg_pixel;
-       gui.menu_bg_pixel = gui.menu_def_bg_pixel;
-       gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
-       gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
+       gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name);
+       gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name);
+       gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name);
+       gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name);

Putting it all in this patch, the result is good for all the forms I tested, as long as one gets rid of shadowThickness in a dark theme:

From top to bottom:

$ xrdb ~/.Xresources; seq 1 12 | gvim -
$ xrdb ~/.Xresources; seq 1 12 | gvim - -xrm 'Vim*shadowThickness: 0'
$ xrdb /dev/null;     seq 1 12 | gvim - -u NONE
$ xrdb /dev/null;     seq 1 12 | gvim - -u NONE -xrm 'Vim*scrollForeground: red' -xrm 'Vim*scrollBackground:blue'

@brammool
Copy link
Contributor

brammool commented Mar 12, 2022 via email

@qsmodo
Copy link
Contributor Author

qsmodo commented Mar 12, 2022

That is what Athena does. I would think gui.menu_def_fg_pixel has the
value from gui.rsrc_menu_fg_name. They are set in
gui_x11_create_widgets() and gui_mch_create_scrollbar().
What is missing here? The color may have been overruled by the
"Scrollbar" highlight group, after using the resources.

Sorry, I don't quite understand what you mean. gui_athena.c does this, but gui_motif.c doesn't.

As far as I know, one can't just do

	XtVaGetValues(menuBar,
	    XmNbackground, &gui.menu_def_bg_pixel,
	    XmNforeground, &gui.menu_def_fg_pixel,
	    NULL);

(and similarly for the scrollbar) and expect to retrieve what the user has chosen as Vim.{menu,scrollbar}{Background,Foreground} in its X resources file because that is not a canonical resource structure and therefore Xt is oblivious to them. So Xt always retrieves the default, hardcoded value instead of the user defined one. The canonical structure would be of the kind Vim*scrollBar.background: color and Vim*menuBar.background: color, and if you set that in your X-resources, you won't need gui_get_color; but the former structure, not the latter, is what :h gui-resources documents.

@brammool
Copy link
Contributor

brammool commented Mar 12, 2022 via email

@qsmodo
Copy link
Contributor Author

qsmodo commented Mar 13, 2022

That should have higher priority than X resources (which are not that
easy to figure out for an averge Vim user).

According to my tests, the patch does exactly that. Did you observe a different behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants