compositor: add weston_surface_set_label_func()

When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces.  Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.

Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.

Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.

v2: renamed 'description' to 'label', so we get
	weston_surface_set_label_func().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
compositor: Implement JSON-timeline logging

Logging is activated and deactivated with the debug key binding 't'.
When activated, it creates a new log file, where it records the events.
The log file contains events and detailed object information entries in
JSON format, and is meant to be parsed in sequence from beginning to the
end.

The emitted events are mostly related to the output repaint cycle, like
when repaint begins, is submitted to GPU, and when it completes on a
vblank. This is recorded per-output. Also some per-surface events are
recorded, including when surface damage is flushed.

To reduce the log size, events refer to objects like outputs and
surfaces by id numbers. Detailed object information is emitted only as
needed: on the first object occurrence, and afterwards only if
weston_timeline_object::force_refresh asks for it.

The detailed information for surfaces includes the string returned by
weston_surface::get_label. Therefore it is important to set
weston_timeline_object::force_refresh = 1 whenever the string would
change, so that the new details get recorded.

A rudimentary parser and SVG generator can be found at:
https://github.com/ppaalanen/wesgr

The timeline logs can answer questions including:
- How does the compositor repaint cycle work timing-wise?
- When was the vblank deadline missed?
- What is the latency from surface commit to showing the new content on
  screen?
- How long does it take to process the scenegraph?

v2: weston_surface::get_description renamed to get_label.
v3: reafctor a bit into fprint_quoted_string().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
tests:  Fix minor typo
xwm: fix a crash in handle_state

To produce the bug, build and run: (you don't need the game data to test)

https://github.com/clintbellanger/flare-engine/

$ mv ~/.config/flare ~/.config/flare.bak
$ ./flare  # click 'configure', set full screen mode then click 'ok'
           # weston will crash and dump core.

[Pekka: edited the commit message]
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
window: use roundtrip instead of dispatch after get_registry

wl_display_dispatch() just dispatches events that are in
default and display queues and if there are no events,
then it will wait for them. But only dispatching
the events doesn't guarantee that we got all the global announcements,
we need to do sync too. Therefore use wl_display_roundtrip() instead
of wl_display_dispatch().

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
screenshooter: fix various memory handling

There were unchecked malloc and no free for this memory.
Also simplify error handling in one function.

v2. remove check if memory is NULL, according to man pages,
    free(NULL) is a no-op

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
clipboard: set fd member of clipboard_source

The fd member of clipboard_source structure was not set
but was used in close().

v2. don't do unnecessary changes

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
compositor: Propagate errors from module_init

load_modules currently ignores errors signalled by both
weston_load_module and module_init, and instead always returns 0. Its
return value appears to be checked in callers, so we most likely want to
propagate any errors.

Signed-off-by: Ondřej Majerech <majerech.o@gmail.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: Say something when configuration is missing

When ivi-module is not set in weston.conf, we probably want to tell the
user about their error instead of just dying.

Signed-off-by: Ondřej Majerech <majerech.o@gmail.com>
[Pekka: include Tanibata's suggestion, fix file name, fix surrounding
coding style]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: clean-up transition animation code.

ivi_layout_transition_layer_render_order is not necesary called. Remove
the method and methods called by it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: clean up unnecesary header

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: reordering method in ivi_layout.c

In the future, re-alignmenet of WL_EXPORT per method should be done.
For that work, re-ordering is required to be used by another method.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: several ivi-layout interfaces moved accross source.

Interfaces for properties setting shall be implemented in ivi-layout.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: make ivi-layout.c as a part of ivi-shell.so

ivi-layout.so is separately built and loaded by using dlopen with
RTLD_GLOBAL. This was because these apis defined in ivi-layout.so shall
be used by ivi-modules; e.g. hmi-controller. This shall be improved that
a struct ivi_layout_api contains the whole exported API as function
pointers to be exposed as module_init.

This patch alone builds, but loading controller modules at runtime
failes. This failure will be fixed by following patches.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
ivi-shell: rewrite controller API

This fixes the breakage caused by "ivi-shell: make ivi-layout.c as a
part of ivi-shell.so"

hmi-controller.c:
A reference implementation of controller module does not use the layout
functions directly. This get function pointers at controller_module_init
which called by ivi-shell.

ivi-layout-export.h:
Definition of interfaces in a struction: ivi_controller_interface.
function pointers are set at ivi-layout.c.

ivi-layout-private.h:
Definition of some interfaces are remove bucause it is implemented in
ivi-layout.c and set it as function pointer. Several interfaces are kept
here because they are implemented in ivi-layout.c/transition.c but used
in other files.

ivi-layout-transition.c:
remove WL_EXPORT because export is not needed anymore.
remove unnesesary unsed method.

ivi-shell.c:
call controller_module_init of hmi-controller to init it and set
function pointers. If the interface_version is equal or
greater than what hmi_controller was built with, things are pass.
If the interface_version is smaller than what the controller expects,
it has to fail because it cannot work. This is followed the manner,

- never remove a function pointer
- never modify an existing function signature
- additions are allowed at the end of struct ivi_controller_interface
- all function pointers must always be populated and working in
  ivi-shell.so (ivi-layout.c etc.)

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
text: Fix some typos

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
text: Fix coding style

Put the return type on a separate line in function declarations.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
text: Remove unused linked list from input_method_context

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
text: Use bool for input_panel_visible

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
input: swallow the key press event when running a compositor key binding

Reviewed-by: Daniel Stone <daniel.stone@collabora.com>