2022-09-30 21:28:59 +01:00
|
|
|
- [1. How to Contribute](#how-to-contribute)
|
|
|
|
|
- [2. Debugging](#debugging)
|
|
|
|
|
- [3. Packaging](#packaging)
|
|
|
|
|
- [4. Coding Style](#coding-style)
|
|
|
|
|
- [4.1 Linux Kernel Style Basics](#linux-kernel-style-basics)
|
|
|
|
|
- [4.2 Devault Deviations](#devault-deviations)
|
|
|
|
|
- [4.3 Labwc Specifics](#labwc-specifics)
|
|
|
|
|
- [4.3.1 API](#api)
|
|
|
|
|
- [4.3.2 The Use of glib](#the-use-of-glib)
|
|
|
|
|
- [4.3.3 The use of GNU extensions](#the-use-of-gnu-extensions)
|
|
|
|
|
- [4.3.4 Naming Conventions](#naming-conventions)
|
|
|
|
|
- [5. Commit Messages](#commit-messages)
|
|
|
|
|
- [6. Submitting Patches](#submitting-patches)
|
|
|
|
|
- [7. Native Language Support](#native-language-support)
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
# How to Contribute
|
2021-12-03 22:44:06 +00:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
1. Report bugs as github issues. We don't use a template, but try to provide
|
|
|
|
|
some sensible information such as what happened, what you expected to happen
|
|
|
|
|
and steps to reproduce. If applicable try with default configuration. If
|
|
|
|
|
you are able to, try to do some debugging (guidelines below).
|
2021-12-03 22:44:06 +00:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
2. Submit patches as github pull-requests. If you wish to introduces significant
|
|
|
|
|
changes or new features, consult the [scope document], discuss on IRC or via
|
|
|
|
|
a github issue first.
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
# Debugging
|
|
|
|
|
|
|
|
|
|
There is no one-way-fits-all method for debugging, so you have to use your
|
|
|
|
|
antennae and do some detective work.
|
2022-05-26 21:51:17 +01:00
|
|
|
|
|
|
|
|
This section contains some approachies which may prove useful.
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
If the compositor crashes, a good starting point is to produce a backtrace by
|
|
|
|
|
building with ASAN/UBSAN:
|
2022-05-26 21:51:17 +01:00
|
|
|
|
|
|
|
|
```
|
2022-06-03 18:52:35 +01:00
|
|
|
meson -Db_sanitize=address,undefined build/
|
2022-05-26 21:51:17 +01:00
|
|
|
ninja -C build/
|
|
|
|
|
```
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
Get debug log with `labwc -d`. The log can be directed to a file with `labwc -d
|
|
|
|
|
2>log.txt`
|
|
|
|
|
|
|
|
|
|
To see what is happening on the wayland protocol for a specific client, run it
|
|
|
|
|
with environment variable `WAYLAND_DEBUG` set to 1, for example `WAYLAND_DEBUG=1
|
|
|
|
|
foot`.
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
To see what the compositor is doing on the protocol run `labwc` nested (i.e.
|
|
|
|
|
start labwc from a terminal in another instance of labwc or some other
|
|
|
|
|
compositor) with `WAYLAND_DEBUG=server`. This filters out anything from clients.
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
For wayland clients, you can get a live view of some useful info using [wlhax].
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
If you think you've got a damage issue, you can run labwc like this:
|
|
|
|
|
`WLR_SCENE_DEBUG_DAMAGE=highlight labwc` to get a visual indication of damage
|
|
|
|
|
regions.
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
To emulate multiple outputs (even if you only have one physical monitor), run
|
|
|
|
|
with `WLR_WL_OUTPUTS=2 labwc` or similar. See [`wlroots/docs/env_vars.md`] for
|
|
|
|
|
more options.
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
For some types of bugs, it might be useful to find out which mesa driver (.so)
|
|
|
|
|
you are using. This can be done with `EGL_LOG_LEVEL=debug labwc 2>&1 | grep
|
|
|
|
|
MESA-LOADER`
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
To rule out driver issues you can run with `WLR_RENDERER=pixman labwc`
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
You can also get some useful system info with [drm_info].
|
2022-05-26 21:51:17 +01:00
|
|
|
|
2022-05-31 21:44:31 +01:00
|
|
|
Use `sudo libinput debug-events` to show input events.
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
From a terminal you can use `xev -event keyboard` and `wev -f wl_keyboard:key`
|
|
|
|
|
to analyse keyboard events
|
|
|
|
|
|
|
|
|
|
# Packaging
|
2022-03-28 21:39:15 +01:00
|
|
|
|
2022-05-20 22:15:38 +02:00
|
|
|
Some distributions carry labwc in their repositories or user repositories.
|
|
|
|
|
|
|
|
|
|
- @ptrcnull (Alpine)
|
|
|
|
|
- @narrat (Arch)
|
|
|
|
|
- @jbeich (FreeBSD)
|
|
|
|
|
- @adcdam (Slackware)
|
|
|
|
|
|
|
|
|
|
kindly maintain the packages in their respective distro.
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
Let's keep them informed of new releases and any changes that relate to
|
|
|
|
|
packaging. If you are maintaining a labwc package for another distro feel free
|
|
|
|
|
to open an issue so we can add you to this list.
|
|
|
|
|
|
|
|
|
|
# Coding Style
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
labwc is written in the [Linux kernel coding style] with a small number of
|
|
|
|
|
deviations to align with [Drew Devault's preferred coding style] nameley:
|
|
|
|
|
|
|
|
|
|
1. [Function Declaration](https://git.sr.ht/~sircmpwn/cstyle#function-declarations)
|
|
|
|
|
2. [Braces for one-line statement](https://git.sr.ht/~sircmpwn/cstyle#brace-placement)
|
|
|
|
|
3. [Organisation of header #include statements](https://git.sr.ht/~sircmpwn/cstyle#header-files)
|
|
|
|
|
4. [Breaking of long lines](https://git.sr.ht/~sircmpwn/cstyle#splitting-long-lines)
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
The reasons for specifying a style is not that we enjoy creating rules, but
|
|
|
|
|
because it makes reading/maintaining the code and spotting problems much easier.
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
If you are new to this style and want to get going quickly, either just imitate
|
2022-10-14 23:16:01 +01:00
|
|
|
the style around you, or read the summary below and use `./scripts/check` to run
|
2022-09-17 12:41:39 +01:00
|
|
|
some formatting checks.
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
## Linux Kernel Style Basics
|
|
|
|
|
|
|
|
|
|
The preferred line length limit is 80 columns, although this is a bit soft.
|
|
|
|
|
|
|
|
|
|
Tabs are 8 columns wide. Identation with spaces is not used.
|
|
|
|
|
|
|
|
|
|
Opening braces go on the same line, except for function definitions.
|
|
|
|
|
|
|
|
|
|
Put `*` with the identifier when defining pointers, for example `char *foo`
|
|
|
|
|
|
|
|
|
|
Spaces are placed around binary operators but not unary, like this:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
int x = y * (2 + z);
|
|
|
|
|
foo(--a, -b);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
`sizeof(*foo)` is preferred over `sizeof(struct foo)`
|
|
|
|
|
|
|
|
|
|
Use `if (!p)` instead of `if (p == 0)` or `if (p == NULL)`
|
|
|
|
|
|
|
|
|
|
Comments are written as follows:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/* This is a single-line comment */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is a multi-line comment which is much much much much much much
|
|
|
|
|
* longer.
|
|
|
|
|
*/
|
|
|
|
|
```
|
2022-09-17 12:41:39 +01:00
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
When documenting functions in header files we use the [kernel-doc format]:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* function_name() - Brief description of function.
|
|
|
|
|
* @arg1: Describe the first argument.
|
|
|
|
|
* @arg2: Describe the second argument.
|
|
|
|
|
* One can provide multiple line descriptions
|
|
|
|
|
* for arguments.
|
|
|
|
|
*
|
|
|
|
|
* A longer description, with more discussion of the function function_name()
|
|
|
|
|
* that might be useful to those using or modifying it. Begins with an
|
|
|
|
|
* empty comment line, and may include additional embedded empty
|
|
|
|
|
* comment lines.
|
|
|
|
|
*
|
|
|
|
|
* The longer description may have multiple paragraphs.
|
|
|
|
|
*
|
|
|
|
|
* Return: Describe the return value of function_name.
|
|
|
|
|
*
|
|
|
|
|
* The return value description can also have multiple paragraphs, and should
|
|
|
|
|
* be placed at the end of the comment block.
|
|
|
|
|
*/
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Devault Deviations
|
|
|
|
|
|
|
|
|
|
Functions are defined as below with `name` on a new line:
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
return type
|
|
|
|
|
name(parameters...)
|
|
|
|
|
{
|
|
|
|
|
body
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
Braces are mandatory even for one-line statements.
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
if (cond) {
|
|
|
|
|
...
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
`#include` statements at the top of the file are organized by locality (`<>`
|
|
|
|
|
first, then `""`), then alphabetized.
|
2022-03-28 21:39:15 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
When breaking a statement onto several lines, indent the subsequent lines once.
|
2022-09-30 21:28:59 +01:00
|
|
|
If the statement declares a `{}` block, indent twice instead. Also, place
|
|
|
|
|
operators (for example `&&`) on the next line.
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
```
|
2022-09-30 21:28:59 +01:00
|
|
|
if (seat->pressed.surface && ctx->surface != seat->pressed.surface
|
|
|
|
|
&& !update_pressed_surface(seat, ctx)
|
|
|
|
|
&& !seat->drag_icon) {
|
|
|
|
|
if (cursor_has_moved) {
|
|
|
|
|
process_cursor_motion_out_of_surface(server, time_msec);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-17 12:41:39 +01:00
|
|
|
```
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
## Labwc Specifics
|
|
|
|
|
|
|
|
|
|
### API
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
We have a very small, modest API and encourage you to use it.
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
1. `znew()` - as a shorthand for calloc(1, sizeof()) with type checking
|
|
|
|
|
[common/mem.h]
|
2022-09-17 12:41:39 +01:00
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
2. `zfree()` to zero after free - [common/mem.h]
|
2022-09-17 12:41:39 +01:00
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
3. `wl_list_append()` to add elements at end of lists - [common/list.h]
|
2022-09-17 12:41:39 +01:00
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
### The Use of glib
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
We try to keep the use of glib pretty minimal for the following reasons:
|
|
|
|
|
|
|
|
|
|
- The use of glib has been known to make AddressSanitiser diagnose false
|
|
|
|
|
positives and negatives.
|
|
|
|
|
- Log messages coming from glib functions look inconsistent.
|
|
|
|
|
- The use of glib functions, naming-conventions and iterators in a code base
|
|
|
|
|
that is predominantly ANSI C creates a clash which makes readability and
|
|
|
|
|
maintainability harder.
|
|
|
|
|
- Mixing gmalloc()/malloc() and respective free()s can create problems with
|
|
|
|
|
memory pools [^1]
|
|
|
|
|
|
|
|
|
|
Having said that, with our use of cairo and pango we depend on glib-2.0 anyway
|
|
|
|
|
so linking with it and making use of some of its helper functions comes for free
|
|
|
|
|
and can keep the code simpler.
|
|
|
|
|
|
|
|
|
|
For example, if we were going to carry out extensive string manipulation,
|
|
|
|
|
GString and utf8 helpers would be okay. Some functions such as
|
|
|
|
|
`g_utf8_casefold()` would be pretty hard to write from scratch and are fine to
|
2022-09-30 21:28:59 +01:00
|
|
|
use. Having said that, labwc does not do much string-mangling.
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
The following functions are used today and are deemed acceptable by the core
|
|
|
|
|
devs:
|
|
|
|
|
|
|
|
|
|
- `g_shell_parse_argv()`
|
|
|
|
|
- `g_strsplit()`
|
2022-09-30 21:28:59 +01:00
|
|
|
- `g_pattern_match_simple()`
|
2022-09-17 12:41:39 +01:00
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
When using these types of functions it is often desirable to support with some
|
|
|
|
|
glib code, which is okay provided it is kept local and self-contained. See
|
|
|
|
|
example from `src/theme.c`:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
static bool
|
|
|
|
|
match(const gchar *pattern, const gchar *string)
|
|
|
|
|
{
|
|
|
|
|
GString *p = g_string_new(pattern);
|
|
|
|
|
g_string_ascii_down(p);
|
|
|
|
|
bool ret = (bool)g_pattern_match_simple(p->str, string);
|
|
|
|
|
g_string_free(p, true);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### The use of GNU extensions
|
2022-09-17 12:41:39 +01:00
|
|
|
|
|
|
|
|
We avoid [GNU C extensions] because we want to fit into the eco-system
|
|
|
|
|
(wayland and wlroots) we live in.
|
|
|
|
|
|
|
|
|
|
We do use `__typeof__` which strictly speaking is a GNU C extension (`typeof`)
|
|
|
|
|
but through the use of `__` is supported by gcc and clang without defining
|
|
|
|
|
`_GNU_SOURCE`. The justification for this is that Wayland uses it, for example
|
|
|
|
|
in the [`wl_container_of()`] macro which is needed in `wl_list*` and it
|
|
|
|
|
does provide pretty big benefits in terms of type safety.
|
|
|
|
|
|
|
|
|
|
We compile with `-std=c11` because that's what 'wlroots' uses and we do not
|
|
|
|
|
want to increase the entry-level for OSs without good reason (and currently
|
|
|
|
|
we can't think of one).
|
|
|
|
|
|
2022-09-30 21:28:59 +01:00
|
|
|
### Naming Conventions
|
|
|
|
|
|
|
|
|
|
There are three types of coordinate systems: surface, output and layout - for
|
|
|
|
|
which the variables (sx, sy), (ox, oy) and (lx, ly) are used respectively in
|
|
|
|
|
line with wlroots.
|
|
|
|
|
|
|
|
|
|
With the introduction of the scene-graph API, some wlroots functions also use
|
|
|
|
|
node coordinates (nx, ny) but we prefer (sx, sy) where possible.
|
|
|
|
|
|
|
|
|
|
We do not worry about namespace issues too much and we try to not make the code
|
|
|
|
|
a pain to use just to uniquify names. If we were writing a library we would
|
|
|
|
|
prefix public functions and structs with `lab_`, but we are not. We do however
|
|
|
|
|
prefix public function names with the filename of the translation unit. For
|
|
|
|
|
example, public functions in `view.c` begin with `view_`.
|
|
|
|
|
|
|
|
|
|
We do start enums with `LAB_`
|
|
|
|
|
|
|
|
|
|
We use the prefix `handle_` for signal-handler-functions in order to be
|
|
|
|
|
consistent with sway and rootston. For example
|
|
|
|
|
`view->request_resize.notify = handle_request_resize`
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
# Commit Messages
|
|
|
|
|
|
|
|
|
|
The log messages that explain changes are just as important as the changes
|
|
|
|
|
themselves. Try to describe the 'why' to help future developers.
|
2021-12-03 23:14:52 +00:00
|
|
|
|
2021-12-26 23:14:21 +00:00
|
|
|
Write [commit messages] like so, keeping the top line to this sort of syntax:
|
2021-12-03 22:44:06 +00:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cursor: add special feature
|
|
|
|
|
```
|
|
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
This first line should:
|
|
|
|
|
|
|
|
|
|
- Be a short description
|
|
|
|
|
- In most cases be prefixed with "area: " where area refers to a filename
|
|
|
|
|
or identifier for the general area of the code being modified.
|
|
|
|
|
- Not capitalize the first word following the "area: " prefix, unless
|
|
|
|
|
it's a name, acronym or similar.
|
|
|
|
|
- Skip the full stop
|
2021-12-26 23:14:21 +00:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
And please wrap the commit message at max 74 characters, otherwise `git log`
|
|
|
|
|
and similar look so weird. URLs and other references are exempt.
|
|
|
|
|
|
|
|
|
|
# Submitting patches
|
|
|
|
|
|
|
|
|
|
Base both bugfixes and new features on `master`.
|
|
|
|
|
|
|
|
|
|
# Native Language Support
|
2022-05-01 14:38:45 +10:00
|
|
|
|
|
|
|
|
Translators can add their `MY_LOCALE.po` files to the `po` directory
|
2022-09-17 12:41:39 +01:00
|
|
|
based on `po/labwc.pot` and issue a pull request. For example:
|
2022-05-01 14:38:45 +10:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
```
|
|
|
|
|
xgettext --keyword=_ --language=C --add-comments -o po/labwc.pot src/menu/menu.c
|
|
|
|
|
```
|
2022-03-28 21:35:59 +01:00
|
|
|
|
2022-09-17 12:41:39 +01:00
|
|
|
[See this tutorial for further guidance](https://www.labri.fr/perso/fleury/posts/programming/a-quick-gettext-tutorial.html)
|
|
|
|
|
|
|
|
|
|
[scope document]: https://github.com/labwc/labwc-scope#readme
|
|
|
|
|
[`wlroots/docs/env_vars.md`]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/docs/env_vars.md
|
|
|
|
|
[wlhax]: https://git.sr.ht/~kennylevinsen/wlhax
|
|
|
|
|
[drm_info]: https://github.com/ascent12/drm_info
|
2022-09-30 21:28:59 +01:00
|
|
|
[Drew Devault's preferred coding style]: https://git.sr.ht/~sircmpwn/cstyle
|
2022-09-17 12:41:39 +01:00
|
|
|
[Linux kernel coding style]: https://www.kernel.org/doc/html/v4.10/process/coding-style.html
|
2022-09-30 21:28:59 +01:00
|
|
|
[kernel-doc format]: https://docs.kernel.org/doc-guide/kernel-doc.html
|
|
|
|
|
[common/mem.h]: https://github.com/labwc/labwc/blob/master/include/common/mem.h
|
|
|
|
|
[common/list.h]: https://github.com/labwc/labwc/blob/master/include/common/list.h
|
2021-12-03 22:44:06 +00:00
|
|
|
[commit messages]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/CONTRIBUTING.md#commit-messages
|
2022-09-17 12:41:39 +01:00
|
|
|
[GNU C extensions]: https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
|
|
|
|
|
[`wl_container_of()`]: https://github.com/wayland-project/wayland/blob/985ab55d59db45ea62795c76dff5949343e86b2f/src/wayland-util.h#L409
|
|
|
|
|
|
|
|
|
|
[^1]: The reference docuementation for glib notes that:
|
|
|
|
|
"It's important to match g_malloc() with g_free(), plain malloc() with
|
|
|
|
|
free(), and (if you're using C++) new with delete and new[] with
|
|
|
|
|
delete[]. Otherwise bad things can happen, since these allocators may use
|
|
|
|
|
different memory pools (and new/delete call constructors and
|
|
|
|
|
destructors)."
|
|
|
|
|
See: https://developer.gimp.org/api/2.0/glib/glib-Memory-Allocation.html
|
|
|
|
|
|