+ All Categories
Home > Documents > Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets...

Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets...

Date post: 04-Jul-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
28
Theming GTK3 widgets with CSS Cosimo Cecchi <[email protected]> Desktop Summit 2011 August 7, 2011
Transcript
Page 1: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

Theming GTK3 widgets with CSS

Cosimo Cecchi<[email protected]>

Desktop Summit 2011August 7, 2011

Page 2: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

Agenda

1 History

2 CSS

3 GTK3 Theming

4 Questions

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 2/29

Page 3: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK theming model 10000ft overview

GTK applications → set of widgets

Widgets → drawing functions

Drawing functions → overridden by themes

GTK theming system → GTK engines

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 3/29

Page 4: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK2 Theming - Engines

GTK2 Engines

implement the gtk paint * methods

custom engine-specific rendering properties

access the GtkWidget itself → powerful

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 4/29

Page 5: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK2 Theming - GtkRC

Custom text format to describe and configure GTK2 options

style classes

set widget style properties and engine custom renderingproperties

class/widget class/widget name matchers

association matchers → style classes

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 5/29

Page 6: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK2 Theming - Problems

GtkRC base syntax very limited and not expressive

dozens of very specialized different engines

modifying an engine is difficult (C code...)

no standard way to render a desired effect

no standard way of testing regressions

accessing GTK internals from the engine

weak separation between content and presentation

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 6/29

Page 7: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

CSS - Universal language

CSS is a markup language designed to enable separation between adocument content and its presentation semantics

W3C standard

well-known syntax, documentation widely available on the web

natively supports a large superset of the GtkRC features

no need to worry about whether a feature is supported in aspecific engine

well-maintained dynamic standard, in continuous evolutiondriven by the web

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 7/29

Page 8: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

CSS - Clear semantics

Using CSS enables a clear disambiguation on the meaning of styleproperties

style properties semantics are predictable, and can be tested(reftests)

CSS Box model (padding, margin, border)

inheritance

font properties

shorthand properties

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 8/29

Page 9: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

CSS - Cool Effects

CSS3 specification draft → family of appealing/rich visual featuresand effects

border-image

box-shadow

text-shadow

nth-child and siblings styling support

gradient support (not yet formalized by W3C, supported as-gtk-gradient in GTK)

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 9/29

Page 10: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

CSS - Cool Effects

Not all the CSS style properties make sense in a toolkit like GTK

OTOH GTK might need some specific properties which wouldn’tmake sense in the web

icon-shadow

transition

add your favorite $property here...

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 10/29

Page 11: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkStyleContext

GtkStyleContext → GtkStyle on steroids

application-side interface to drawing and theming

each widget holds its own different context

independent from GtkWidget, operates on GtkWidgetPathstructures

GtkWidgetPath contains information for generic toplevel →child widget hierarchies

easy styling of foreign toolkits (WebKit, QT, ...)

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 11/29

Page 12: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkStyleContext

Style classes.scrollbar → .slider + .trough + .button

conceptually decompose a widget in a set of one or more baseelements

apply a style to each base widget element

same widget → lots of possibilities without touching code.toolbar vs .primary-toolbar

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 12/29

Page 13: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkStyleContext

Widget regionsGtkTreeView → row, column, column-header

number of repeated elements of the same type in a widget notknown

named class + a set of order-based flagseven, odd, first, last, sorted

use nth-child to match the desired flag from the CSS

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 13/29

Page 14: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkStyleContext

Native nth-child support in containers

construct a selector matching the position of an element inrelation to its siblings

works by default for widgets packed in GtkBox andGtkToolbar

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 14/29

Page 15: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkStyleContext

animatable regions

of course get/set style properties as GtkStyle used to

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 15/29

Page 16: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkThemingEngine

Theme-side counterpart of GtkStyleContext

Calls into cairo to do the actual rendering

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 16/29

Page 17: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - GtkThemingEngine

Theme-side counterpart of GtkStyleContext

default implementation inside GTK+

external theming engines → subclass + .so module library

no access to GTK internals

access to all the style information stored in GtkStyleContext

register custom style properties

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 17/29

Page 18: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - Theme developers

Where we want to be

You should not write a GtkThemingEngine subclass unless youhave a very good reason to

You should be able to do everything you need with CSS and SVGassets

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 18/29

Page 19: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - Theme developers

Where we are right now

Not yet possible to write a full-featured complex theme (e.g.Adwaita) entirely in CSS and SVG

features missing from GTK

multiple layer of backgroundsinconsistent focus theming properties

hard GTK limitations

not possible to render outside the widget allocation box

working around widget bugs

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 19/29

Page 20: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - Theme developers

Where we are right now

Not yet possible to write a full-featured complex theme (e.g.Adwaita) entirely in CSS and SVG

But...

Adwaita is now ∼90% CSS and SVG

about 1000 lines of C code

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 20/29

Page 21: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - Theme developers

Upstream GTK is very receptive about improving the CSS themingengine and adding support for additional style properties

if you’re writing a custom style property, please consider usinga CSS standard and pushing it upstream

file bugs, write patches, talk to us

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 21/29

Page 22: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - App developers

Should applications completely specify a customized look likewebsites do?

Two schools of thought

1 applications know better

2 themes know better

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 22/29

Page 23: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - App developers

The theme always knows better

Except when an application really needs to force a completelyunique look altogether

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 23/29

Page 24: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - App developers

The theme always knows better

hardcoded colors in applications → basically unthemable

the engine lacks constructs to fully describe a complex layoutto matchthe first sidebar left of a view widget

CSS3 has such constructs (nth-child and friends) - weshould extend our support for them

special-casing app widgets or layouts in the theme instead ofhardcoding theme information in the apps

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 24/29

Page 25: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - App developers

When an app needs to force an unique look altogether...

Pro-oriented (e.g. Ardour)Games, educational or unconventionalSpecial accessibility requirements

using a custom CSS theme makes a lot of things very easy

apps could even install and use their own theming enginemodule to bypass the default gtk render * implementations

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 25/29

Page 26: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - Future

drop Raleigh as default GTK theme (?!)

integrate documentation for the style classes defined by stockwidgets

tie style classes to HIG 3.0 recommendations

multiple background compositing

sanity-check our implementation of focus theming

easier theming for GtkCellRenderers

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 26/29

Page 27: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

GTK3 Theming - Blue sky future

fully implement the CSS box-model logic in GTK

make every widget capable of rendering a frame and abackground

improved use of implicit animations

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 27/29

Page 28: Theming GTK3 widgets with CSS...GTK theming model 10000ft overview GTK applications !set of widgets Widgets !drawing functions Drawing functions !overridden by themes GTK theming system

Thanks for attending

Questions?

Cosimo Cecchi — Theming GTK3 widgets with CSS — Desktop Summit — Berlin 28/29


Recommended