* Dependent colours
@ 2022-04-14 13:00 Lars Ingebrigtsen
2022-04-14 13:36 ` Lars Ingebrigtsen
2022-04-14 13:48 ` Eli Zaretskii
0 siblings, 2 replies; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-14 13:00 UTC (permalink / raw)
To: emacs-devel@gnu.org
In many situations, packages and users need to specify colours to use
for something. We generally defer this to the face machinery, because
which colours to use for something might depend on whether you have a
light or dark background, or whether it's a GUI Emacs or a terminal one,
etc.
This works well as a machinery, but it's pretty cumbersome when the user
just wants to specify a list of colours.
So I'm wondering whether we could create something that would make
things easier for the user here, and if anybody had any thoughts on the
issue.
Off the top of my head... if we had something like
(make-color "red")
(make-color ((background light) "blue")
((background dark) "red"))
Uhm... Or something... better... :-)
Anyway, code that uses these colour objects would then create real
(dynamic) faces out of them, eventually, so that there'd be no change in
the display engine (I think).
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 13:00 Dependent colours Lars Ingebrigtsen
@ 2022-04-14 13:36 ` Lars Ingebrigtsen
2022-04-14 14:11 ` Stefan Monnier
2022-04-14 13:48 ` Eli Zaretskii
1 sibling, 1 reply; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-14 13:36 UTC (permalink / raw)
To: emacs-devel
Lars Ingebrigtsen <larsi@gnus.org> writes:
> (make-color ((background light) "blue")
> ((background dark) "red"))
>
> Uhm... Or something... better... :-)
I think we get to 99.7% of the use cases with just light/dark.
So (make-color "blue" "red") would probably be the shortest syntax we
could use here. (The first for light backgrounds and the second for
dark.) Or just (color "blue" "red"), since the point is to have
something short and convenient for people.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 13:36 ` Lars Ingebrigtsen
@ 2022-04-14 14:11 ` Stefan Monnier
2022-04-14 14:14 ` Lars Ingebrigtsen
0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2022-04-14 14:11 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> So (make-color "blue" "red") would probably be the shortest syntax we
> could use here. (The first for light backgrounds and the second for
> dark.) Or just (color "blue" "red"), since the point is to have
> something short and convenient for people.
You mean like
(defun make-color (light dark)
(if (frame--current-backround-mode (selected-frame)) dark light))
Or do you have something more sophisticated in mind?
Stefan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 13:00 Dependent colours Lars Ingebrigtsen
2022-04-14 13:36 ` Lars Ingebrigtsen
@ 2022-04-14 13:48 ` Eli Zaretskii
2022-04-14 13:56 ` Lars Ingebrigtsen
1 sibling, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2022-04-14 13:48 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Thu, 14 Apr 2022 15:00:55 +0200
>
> In many situations, packages and users need to specify colours to use
> for something. We generally defer this to the face machinery, because
> which colours to use for something might depend on whether you have a
> light or dark background, or whether it's a GUI Emacs or a terminal one,
> etc.
>
> This works well as a machinery, but it's pretty cumbersome when the user
> just wants to specify a list of colours.
>
> So I'm wondering whether we could create something that would make
> things easier for the user here, and if anybody had any thoughts on the
> issue.
>
> Off the top of my head... if we had something like
>
> (make-color "red")
>
> (make-color ((background light) "blue")
> ((background dark) "red"))
>
> Uhm... Or something... better... :-)
I'm not sure I understand: we already have anonymous faces one can get
by specifying just the colors, as in
'(:foreground "red" :background "blue")
Why is that not enough?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 13:48 ` Eli Zaretskii
@ 2022-04-14 13:56 ` Lars Ingebrigtsen
2022-04-14 16:10 ` Eli Zaretskii
0 siblings, 1 reply; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-14 13:56 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
> I'm not sure I understand: we already have anonymous faces one can get
> by specifying just the colors, as in
>
> '(:foreground "red" :background "blue")
>
> Why is that not enough?
It's not about foreground or background colours, it's about choosing a
colour based on features of the current frame, like defface.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 13:56 ` Lars Ingebrigtsen
@ 2022-04-14 16:10 ` Eli Zaretskii
2022-04-14 16:13 ` Lars Ingebrigtsen
0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2022-04-14 16:10 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Thu, 14 Apr 2022 15:56:53 +0200
> Cc: emacs-devel@gnu.org
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > I'm not sure I understand: we already have anonymous faces one can get
> > by specifying just the colors, as in
> >
> > '(:foreground "red" :background "blue")
> >
> > Why is that not enough?
>
> It's not about foreground or background colours, it's about choosing a
> colour based on features of the current frame, like defface.
But the result should be a face, right? So you want an easy-to-use
facility to create a face that depends on the background-mode? Or am
I misunderstanding again? And if I am misunderstanding, can you
please describe the use case in more detail?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 16:10 ` Eli Zaretskii
@ 2022-04-14 16:13 ` Lars Ingebrigtsen
2022-04-14 16:23 ` Eli Zaretskii
0 siblings, 1 reply; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-14 16:13 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
> But the result should be a face, right?
It could be a face, but not necessarily. Dynamically creating an SVG
with a different foreground colour depending on the frame, for instance.
> So you want an easy-to-use facility to create a face that depends on
> the background-mode? Or am I misunderstanding again? And if I am
> misunderstanding, can you please describe the use case in more detail?
defface is easy enough to use if you want to create a face, but here the
interface we're presenting the user with is tied to colours, not faces.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 16:13 ` Lars Ingebrigtsen
@ 2022-04-14 16:23 ` Eli Zaretskii
2022-04-15 8:46 ` Lars Ingebrigtsen
0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2022-04-14 16:23 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Thu, 14 Apr 2022 18:13:56 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > But the result should be a face, right?
>
> It could be a face, but not necessarily. Dynamically creating an SVG
> with a different foreground colour depending on the frame, for instance.
Are there any other examples besides the background of SVG? Because
the latter is AFAIR very special, and we can now handle it through
faces as well. So the question is: do we need to do this outside of
the faces realm? I cannot think of any other case where we use colors
not via faces.
> > So you want an easy-to-use facility to create a face that depends on
> > the background-mode? Or am I misunderstanding again? And if I am
> > misunderstanding, can you please describe the use case in more detail?
>
> defface is easy enough to use if you want to create a face, but here the
> interface we're presenting the user with is tied to colours, not faces.
Interactively or non-interactively?
Anyway, colors in Emacs are face attributes.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-14 16:23 ` Eli Zaretskii
@ 2022-04-15 8:46 ` Lars Ingebrigtsen
2022-04-15 9:32 ` Eli Zaretskii
0 siblings, 1 reply; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-15 8:46 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
> Anyway, colors in Emacs are face attributes.
Colours are colours, but we usually use the face machinery to specify
them, and we (almost always) instantiate them on the screen via the face
machinery. That doesn't mean that colours per se are face attributes.
The reason I started thinking about these things, once again, is because
vtable allows you to specify (alternating) row and column background
colours, and where they intersect, vtable computes the blend of colours.
The obvious way people to use this is to say
:column-colors '("red" "blue")
:row-colors '("green" "yellow")
and that's it. But pondering this a bit more, perhaps using faces here
would be nicer anyway -- the package writer may be wanting to use
alternating foreground colours on the rows anyway. So
:column-colors '((:background "red") (:background "blue"))
:row-colors '((:foreground "green") (:foreground "yellow"))
is more expressive. (And vtable will just have to check both foreground
and background colours on the faces and blend accordingly, but that's
just a small matter of programming.)
And besides, using faces for things like this has the advantage of
fitting into the theming architecture. I mean, if it's
:column-colors '(list-timer-column-even list-timer-column-odd)
and those are faces, we don't have to extend the theming machinery to
handle theming of colours.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-15 8:46 ` Lars Ingebrigtsen
@ 2022-04-15 9:32 ` Eli Zaretskii
2022-04-15 9:48 ` Lars Ingebrigtsen
0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2022-04-15 9:32 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Fri, 15 Apr 2022 10:46:03 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > Anyway, colors in Emacs are face attributes.
>
> Colours are colours, but we usually use the face machinery to specify
> them, and we (almost always) instantiate them on the screen via the face
> machinery. That doesn't mean that colours per se are face attributes.
I'm probably missing something: what other means do we have in Emacs
to produce colors on display, except via faces?
> :column-colors '("red" "blue")
> :row-colors '("green" "yellow")
>
> and that's it. But pondering this a bit more, perhaps using faces here
> would be nicer anyway -- the package writer may be wanting to use
> alternating foreground colours on the rows anyway. So
>
> :column-colors '((:background "red") (:background "blue"))
> :row-colors '((:foreground "green") (:foreground "yellow"))
>
> is more expressive. (And vtable will just have to check both foreground
> and background colours on the faces and blend accordingly, but that's
> just a small matter of programming.)
>
> And besides, using faces for things like this has the advantage of
> fitting into the theming architecture. I mean, if it's
>
> :column-colors '(list-timer-column-even list-timer-column-odd)
>
> and those are faces, we don't have to extend the theming machinery to
> handle theming of colours.
If what you have in mind can play nicely with faces (and I think it
can, but I'm not yet sure I understand the issue, see above), then
yes, using face machinery is the best, as we have there a lot of
functionalities that can be used without effort.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-15 9:32 ` Eli Zaretskii
@ 2022-04-15 9:48 ` Lars Ingebrigtsen
2022-04-15 10:32 ` Po Lu
2022-04-15 10:38 ` Eli Zaretskii
0 siblings, 2 replies; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-15 9:48 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
>> Colours are colours, but we usually use the face machinery to specify
>> them, and we (almost always) instantiate them on the screen via the face
>> machinery. That doesn't mean that colours per se are face attributes.
>
> I'm probably missing something: what other means do we have in Emacs
> to produce colors on display, except via faces?
I think I mentioned SVGs already? But we also have the mouse pointer,
and tooltip colours, and various bits and bobs in the toolkits that take
colours as parameters (for menus and scroll bars and etc).
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-15 9:48 ` Lars Ingebrigtsen
@ 2022-04-15 10:32 ` Po Lu
2022-04-15 10:37 ` Lars Ingebrigtsen
2022-04-15 10:38 ` Eli Zaretskii
1 sibling, 1 reply; 18+ messages in thread
From: Po Lu @ 2022-04-15 10:32 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel
Lars Ingebrigtsen <larsi@gnus.org> writes:
> I think I mentioned SVGs already?
That's handled by librsvg and is AFAICT outside the control of Emacs. A
better example would be XPM images, where the color allocation is in
fact done by Emacs.
> But we also have the mouse pointer, and tooltip colours, and various
> bits and bobs in the toolkits that take colours as parameters (for
> menus and scroll bars and etc).
The tooltip colors are defined via faces, while the menu and scroll bar
colors are in fact supposed to be defined via faces, if you set aside
the frame parameters.
The `mouse' face and its associated frame parameter is unfortunately
unlikely to work under the common X sessions these days.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-15 10:32 ` Po Lu
@ 2022-04-15 10:37 ` Lars Ingebrigtsen
2022-04-15 11:12 ` Po Lu
0 siblings, 1 reply; 18+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-15 10:37 UTC (permalink / raw)
To: Po Lu; +Cc: Eli Zaretskii, emacs-devel
Po Lu <luangruo@yahoo.com> writes:
> > I think I mentioned SVGs already?
>
> That's handled by librsvg and is AFAICT outside the control of Emacs.
We can create any SVGs we want via svg.el and display them.
> The tooltip colors are defined via faces, while the menu and scroll bar
> colors are in fact supposed to be defined via faces, if you set aside
> the frame parameters.
We currently define them via the defface machinery. But we do not use
faces to instantiate the colours on the screen, which is what Eli asked
for examples of.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-15 10:37 ` Lars Ingebrigtsen
@ 2022-04-15 11:12 ` Po Lu
0 siblings, 0 replies; 18+ messages in thread
From: Po Lu @ 2022-04-15 11:12 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel
Lars Ingebrigtsen <larsi@gnus.org> writes:
> We currently define them via the defface machinery. But we do not use
> faces to instantiate the colours on the screen, which is what Eli asked
> for examples of.
In most cases we do: the colors are allocated in xfaces.c upon face
realization (see the calls to load_color2 and unload_color.) The image
code path is an exception, and I think inside SVGs it isn't even
possible to use the same color names as in the rest of Emacs.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Dependent colours
2022-04-15 9:48 ` Lars Ingebrigtsen
2022-04-15 10:32 ` Po Lu
@ 2022-04-15 10:38 ` Eli Zaretskii
1 sibling, 0 replies; 18+ messages in thread
From: Eli Zaretskii @ 2022-04-15 10:38 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Fri, 15 Apr 2022 11:48:31 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> Colours are colours, but we usually use the face machinery to specify
> >> them, and we (almost always) instantiate them on the screen via the face
> >> machinery. That doesn't mean that colours per se are face attributes.
> >
> > I'm probably missing something: what other means do we have in Emacs
> > to produce colors on display, except via faces?
>
> I think I mentioned SVGs already? But we also have the mouse pointer,
> and tooltip colours, and various bits and bobs in the toolkits that take
> colours as parameters (for menus and scroll bars and etc).
Some of those are faces, and the rest are not implemented by us.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2022-04-15 11:12 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-14 13:00 Dependent colours Lars Ingebrigtsen
2022-04-14 13:36 ` Lars Ingebrigtsen
2022-04-14 14:11 ` Stefan Monnier
2022-04-14 14:14 ` Lars Ingebrigtsen
2022-04-14 14:57 ` [External] : " Drew Adams
2022-04-14 15:26 ` Lars Ingebrigtsen
2022-04-14 13:48 ` Eli Zaretskii
2022-04-14 13:56 ` Lars Ingebrigtsen
2022-04-14 16:10 ` Eli Zaretskii
2022-04-14 16:13 ` Lars Ingebrigtsen
2022-04-14 16:23 ` Eli Zaretskii
2022-04-15 8:46 ` Lars Ingebrigtsen
2022-04-15 9:32 ` Eli Zaretskii
2022-04-15 9:48 ` Lars Ingebrigtsen
2022-04-15 10:32 ` Po Lu
2022-04-15 10:37 ` Lars Ingebrigtsen
2022-04-15 11:12 ` Po Lu
2022-04-15 10:38 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).