# Live tile examples

Start draws every tile itself. Apps and scripts only say what goes on a
tile, over the session bus: `org.cont8nuum.Tiles1`, served by c8-shell and
documented (fields, templates, sizes) in
`protocols/org.cont8nuum.Tiles1.xml`. A tile is addressed by its id in
`start.ini` (the `[tile ID]` section); an app pinned from All apps has its
desktop file id. c8-shell runs each tile's `provider` command when it
first starts.

Content stays after the sender exits, and c8-shell keeps it across
logins, so a cron job can update a tile and quit.

## c8tile

The command line way in:

```sh
c8tile update mail --tag inbox template=block block=3 \
    text1='new messages' text2='From: alice'
c8tile update news template=peek image=/tmp/hero.jpg \
    heading='Lead story' text1='The first line of it'
c8tile update weather template=block block=12° text1=Cloudy \
    wide.text2='feels 10°' expires=3600
c8tile badge mail 3
c8tile remove mail inbox
c8tile clear mail
c8tile watch mail    # prints "pinned SIZE", "visible N", "activated",
                     # "restarting"
c8tile restart mail  # start the tile's provider again (--all: every tile)
```

Without `--tag` an update replaces everything on the tile; tagged
updates (up to five) take turns. `\t` in a value puts the rest of the
line at the right edge.

Anything that speaks D-Bus can do the same without c8tile:

```sh
gdbus call --session --dest org.cont8nuum.Tiles \
    --object-path /org/cont8nuum/Tiles \
    --method org.cont8nuum.Tiles1.Update mail '' \
    "{'template': 'block', 'block': '3', 'text1': 'new messages'}"
```

## A command as a tile (`disk.widget`)

The least there is to write: a `.widget` file in
`~/.local/share/cont8nuum/widgets/` with a `Command=` line. It is then
under All apps, Live tiles, and pinned, `c8-widget script` runs the
command through `sh` every `Interval` seconds while Start shows (and
when it comes up) and puts what it prints on the tile.

```ini
[Widget]
Name=Disk space
Command=df -h --output=pcent,avail "$HOME" | tail -1 | awk '{ print $1; print $2 " free" }'
Interval=60
Template=block
```

Plain lines: the first is the heading (the big value, for
`Template=block`), the rest the lines under it. Or lines of
`FIELD=VALUE`, the same fields as `c8tile update` takes (`template=`,
`heading=`, `text1=`, `meter=`, `color=`, `wide.text2=`...), for
anything more. A run that fails or prints nothing leaves the tile as it
was; one that takes over 30 seconds is stopped. After changing the
file: `c8tile restart ID` (the file's name without `.widget`).

## c8-sysmon-tile (`sysmon.sh`)

A plain `sh` provider. Every few seconds it reads `/proc/stat` and
`/proc/meminfo` and sends two tagged updates, `cpu` and `mem`, so the tile
takes turns showing each. It gives up after three `c8tile` failures in a
row, which usually means the shell is gone.

```
c8-sysmon-tile [tile-id] [interval-seconds]  # defaults: sysmon, 5
```

```ini
[tile sysmon]
name = System
size = wide
provider = c8-sysmon-tile sysmon 5
```

Set `$C8TILE` to use a `c8tile` binary that is not in `$PATH`.

## c8-widget

`c8-widget KIND [tile-id]` keeps one tile up to date with a clock, the
weather, system load, what's playing and more; `c8-widget --help` lists
the kinds. The `.widget` files in `data/widgets` describe them for All
apps.

## c8-charms-demo (`charms-demo.c`)

Not a tile: a small c8ui "news" app that brings its own Search and
Settings charms through `org.cont8nuum.Charms1` (documented in
`protocols/org.cont8nuum.Charms1.xml`). It owns the bus name
`org.cont8nuum.NewsDemo`, the same as its window's app_id, which is how
the shell finds it. With it in front, Super+S searches its headlines
(Enter shows results in the app, a result opens the story) and Super+I
shows its Options page and About in the Settings flyout.

It is built when c8ui is installed, but not installed:

```sh
desktop/widgets/build/examples/c8-charms-demo
```

A c8ui app gets this from `<c8ui/c8ui-charms.h>`: `c8ui_charms_new(app)`,
then `c8ui_charms_on_search`, `c8ui_charms_add_page` (a function that adds
toggles, choices, sliders… each with a change callback) and
`c8ui_charms_add_action`. The demo is a short example of all of it.

Apps on other toolkits can do the same in any language: serve the
interface at `/org/cont8nuum/Charms` under the app id. Every method is
optional.
