Skip to content

Support prefers-color-scheme (dark mode) #34425

Closed

Description

@nicoburns

Description

prefers-color-scheme is a CSS feature which allows CSS to conditionally set styles based on the user's preference for light or dark mode.

MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
Spec: https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme

Implementation plan

The remaining work is to:

  • Add an embedder event for setting the preferred color scheme
  • Plumb this through to the layout thread where it should be set on the device (possibly via a "reflow", similar to window size?)
  • Connect this to Winit ThemeChanged events in servoshell. We should also obtain an initial value from winit when creating the window.

Activity

  1. added
    E-less-complex
    B-feature-tracking
    good first issue
    C-untriaged
    on Nov 29, 2024
  2. removed
    C-untriaged
    on Nov 29, 2024
  3. arthmis commented on Nov 29, 2024

    @arthmis
    Contributor

    Hi I'm a new contributor and I would like to work on this issue. Is there any context I should know to tackle this issue?

  4. nicoburns commented on Dec 3, 2024

    @nicoburns
    ContributorAuthor

    Hi I'm a new contributor and I would like to work on this issue. Is there any context I should know to tackle this issue?

    You can see the value which needs to be set to enable "dark mode" here: https://github.com/servo/servo/pull/34423/files#diff-110381529b2694b44285f15e5eba966a5b50a20720c5dcedd804766e95d834e0R1128

    That needs to be connected with the Winit ThemeChanged event which can be hooked into here:

    fn queue_embedder_events_for_winit_event(&self, event: winit::event::WindowEvent) {

    The winit event needs to generate a (new) EmbedderEvent https://github.com/servo/servo/blob/main/components/compositing/windowing.rs#L45 that works similarly to the existing WindowResize event (although perhaps passed the new theme inside the EmbedderEvent).

  5. arthmis commented on Dec 3, 2024

    @arthmis
    Contributor

    thank you for laying that all out! I'll get on it then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layout/queryB-feature-trackingE-less-complexgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions