diff --git a/_docs/hacking-howto b/_docs/hacking-howto index c6dd6fa..ae48c44 100644 --- a/_docs/hacking-howto +++ b/_docs/hacking-howto @@ -14,7 +14,7 @@ you find necessary, please do not hesitate to contact me.

++++ This document is not 100% up to date. Specifically, everything up to and -including <> has been updated recently. The rest might contain +including <> has been updated recently. The rest might contain outdated information. ++++

@@ -34,30 +34,18 @@ Guide → Compiling a Meson project]. In case you’re unfamiliar: === Build system features -* We use the +AX_ENABLE_BUILDDIR+ macro to enforce builds happening in a separate - directory. This is a prerequisite for the +AX_EXTEND_SRCDIR+ macro and building - in a separate directory is common practice anyway. In case this causes any - trouble when packaging i3 for your distribution, please open an issue. +* +ninja test+ runs the i3 testsuite. See docs/testsuite for details. -* +make check+ runs the i3 testsuite. See docs/testsuite for details. +* +meson dist+ builds a release tarball and runs tests on the result. -* +make distcheck+ (runs testsuite on +make dist+ result, tiny bit quicker - feedback cycle than waiting for the travis build to catch the issue). +* +meson -Ddocs=true -Dmans=true+ will enable the options to build docs and + manpages. These options require additional dependencies that are normally not + required for users who just want to build i3. -* +make uninstall+ (occasionally requested by users who compile from source) - -* +make+ will build manpages/docs by default if the tools are installed. - Conversely, manpages/docs are not tried to be built for users who don’t want - to install all these dependencies to get started hacking on i3. Manpages and - docs can be disabled with the +--disable-mans++ and ++--disable-docs++ - configure options respectively. - -* non-release builds will enable address sanitizer by default. Use the - +--disable-sanitizers+ configure option to turn off all sanitizers, and see - +--help+ for available sanitizers. - -* Coverage reports are now generated using +make check-code-coverage+, which - requires specifying +--enable-code-coverage+ when calling configure. +* +meson -Db_sanitize=address+ will enable the address sanitizer which is + disabled by default. A summary of memory leaks will be printed on program + exit. This can include false-positives. For other options of the +b_sanitize+ + flag see https://mesonbuild.com/Builtin-options.html. == Pull requests @@ -341,30 +329,26 @@ ensure that the operating system on which i3 is compiled has all the expected features, i3 comes with +include/queue.h+. On BSD systems, you can use +man queue(3)+. On Linux, you have to use google (or read the source). -The lists used are +SLIST+ (single linked lists), +CIRCLEQ+ (circular -queues) and +TAILQ+ (tail queues). Usually, only forward traversal is necessary, -so an +SLIST+ works fine. If inserting elements at arbitrary positions or at -the end of a list is necessary, a +TAILQ+ is used instead. However, for the -windows inside a container, a +CIRCLEQ+ is necessary to go from the currently -selected window to the window above/below. - -== Naming conventions - -There is a row of standard variables used in many events. The following names -should be chosen for those: +The lists used are +SLIST+ (single linked lists), +CIRCLEQ+ (circular queues) +and +TAILQ+ (tail queues). Usually, +TAILQ+ is used which allows inserting +elements at arbitrary positions or at the end of the list. If only forward +traversal is necessary, an +SLIST+ can be used. +CIRCLEQ+ is used just to +manage the X11 state of each window. - * +conn+ is the xcb_connection_t - * +event+ is the event of the particular type - * +con+ names a container - * +current+ is a loop variable when using +TAILQ_FOREACH+ etc. +[[startup]] +== Startup (src/main.c, main()) -== Startup (src/mainx.c, main()) +Among other things, the main() function does the following: * Establish the xcb connection + * Load the i3 config * Check for XKB extension on the separate X connection, load Xcursor - * Check for RandR screens (with a fall-back to Xinerama) + * Set up EWMH hints * Grab the keycodes for which bindings exist + * Check for XRandR screens * Manage all existing windows + * Exec configured startup processes + * Start i3bar if configured * Enter the event loop == Keybindings diff --git a/docs/hacking-howto.html b/docs/hacking-howto.html index 0823334..af1fab1 100644 --- a/docs/hacking-howto.html +++ b/docs/hacking-howto.html @@ -51,7 +51,7 @@

Hacking i3: How To

WARNING!

This document is not 100% up to date. Specifically, everything up to and -including [data_structures] has been updated recently. The rest might contain +including [startup] has been updated recently. The rest might contain outdated information.

@@ -75,48 +75,27 @@

1.1. Build system features

@@ -554,70 +533,61 @@

6. List/queue macros

ensure that the operating system on which i3 is compiled has all the expected features, i3 comes with include/queue.h. On BSD systems, you can use man queue(3). On Linux, you have to use google (or read the source).

-

The lists used are SLIST (single linked lists), CIRCLEQ (circular -queues) and TAILQ (tail queues). Usually, only forward traversal is necessary, -so an SLIST works fine. If inserting elements at arbitrary positions or at -the end of a list is necessary, a TAILQ is used instead. However, for the -windows inside a container, a CIRCLEQ is necessary to go from the currently -selected window to the window above/below.

+

The lists used are SLIST (single linked lists), CIRCLEQ (circular queues) +and TAILQ (tail queues). Usually, TAILQ is used which allows inserting +elements at arbitrary positions or at the end of the list. If only forward +traversal is necessary, an SLIST can be used. CIRCLEQ is used just to +manage the X11 state of each window.

-

7. Naming conventions

+

7. Startup (src/main.c, main())

-

There is a row of standard variables used in many events. The following names -should be chosen for those:

+

Among other things, the main() function does the following:

  • -conn is the xcb_connection_t +Establish the xcb connection

  • -event is the event of the particular type +Load the i3 config

  • -con names a container +Check for XKB extension on the separate X connection, load Xcursor

  • -current is a loop variable when using TAILQ_FOREACH etc. +Set up EWMH hints

  • -
-
-
-
-

8. Startup (src/mainx.c, main())

-
-
  • -Establish the xcb connection +Grab the keycodes for which bindings exist

  • -Check for XKB extension on the separate X connection, load Xcursor +Check for XRandR screens

  • -Check for RandR screens (with a fall-back to Xinerama) +Manage all existing windows

  • -Grab the keycodes for which bindings exist +Exec configured startup processes

  • -Manage all existing windows +Start i3bar if configured

  • @@ -629,10 +599,10 @@

    8. Startup (src/mainx.c, main())

-

9. Keybindings

+

8. Keybindings

-

9.1. Grabbing the bindings

+

8.1. Grabbing the bindings

Grabbing the bindings is quite straight-forward. You pass X your combination of modifiers and the keycode you want to grab and whether you want to grab them actively or passively. Most bindings (everything except for bindings using @@ -653,7 +623,7 @@

9.1. Grabbing the bindings

will handle the event, if not, it will replay the event.

-

9.2. Handling a keypress

+

8.2. Handling a keypress

As mentioned in "Grabbing the bindings", upon a keypress event, i3 first gets the correct state.

Then, it looks through all bindings and gets the one which matches the received @@ -664,7 +634,7 @@

9.2. Handling a keypress

-

10. Manage windows (src/main.c, manage_window() and reparent_window())

+

9. Manage windows (src/main.c, manage_window() and reparent_window())

manage_window() does some checks to decide whether the window should be managed at all:

@@ -700,7 +670,7 @@

10. Manage

-

11. What happens when an application is started?

+

10. What happens when an application is started?

i3 does not care about applications. All it notices is when new windows are mapped (see src/handlers.c, handle_map_request()). The window is then @@ -720,7 +690,7 @@

11. What happens when an a

-

12. _NET_WM_STATE

+

11. _NET_WM_STATE

Only the _NET_WM_STATE_FULLSCREEN and _NET_WM_STATE_DEMANDS_ATTENTION atoms are handled.

@@ -731,7 +701,7 @@

12. _NET_WM_STATE

-

13. WM_NAME

+

12. WM_NAME

When the WM_NAME property of a window changes, its decoration (containing the title) is re-rendered. Note that WM_NAME is in COMPOUND_TEXT encoding which is @@ -740,7 +710,7 @@

13. WM_NAME

-

14. _NET_WM_NAME

+

13. _NET_WM_NAME

Like WM_NAME, this atom contains the title of a window. However, _NET_WM_NAME is encoded in UTF-8. i3 will recode it to UCS-2 in order to be able to pass it @@ -749,7 +719,7 @@

14. _NET_WM_NAME

-

15. Size hints

+

14. Size hints

Size hints specify the minimum/maximum size for a given window as well as its aspect ratio. This is important for clients like mplayer, who only set the @@ -762,7 +732,7 @@

15. Size hints

-

16. Rendering (src/layout.c, render_layout() and render_container())

+

15. Rendering (src/layout.c, render_layout() and render_container())

Rendering in i3 version 4 is the step which assigns the correct sizes for borders, decoration windows, child windows and the stacking order of all @@ -782,7 +752,7 @@

16. Renderin about the different rendering steps, in the order of "top of the tree" (root container) to the bottom.

-

16.1. Rendering the root container

+

15.1. Rendering the root container

The i3 root container (con→type == CT_ROOT) represents the X11 root window. It contains one child container for every output (like LVDS1, VGA1, …), which is available on your computer.

@@ -798,7 +768,7 @@

16.1. Rendering the root container

only called for the global fullscreen window.

-

16.2. Rendering an output

+

15.2. Rendering an output

Output containers (con→layout == L_OUTPUT) represent a hardware output like LVDS1, VGA1, etc. An output container has three children (at the moment): One content container (having workspaces as children) and the top/bottom dock area @@ -845,18 +815,18 @@

16.2. Rendering an output

-

16.3. Rendering a workspace or split container

+

15.3. Rendering a workspace or split container

From here on, there really is no difference anymore. All containers are of con→type == CT_CON (whether workspace or split container) and some of them have a con→window, meaning they represent an actual window instead of a split container.

-

16.3.1. Default layout

+

15.3.1. Default layout

In default layout, containers are placed horizontally or vertically next to each other (depending on the con→orientation).

-

16.3.2. Stacked layout

+

15.3.2. Stacked layout

In stacked layout, only the focused window is actually shown (this is achieved by calling x_raise_con() in reverse focus order at the end of render_con()).

The available space for the focused window is the size of the container minus @@ -867,20 +837,20 @@

16.3.2. Stacked layout

the stacked container.

-

16.3.3. Tabbed layout

+

15.3.3. Tabbed layout

Tabbed layout works precisely like stacked layout, but the window decoration position/size is different: They are placed next to each other on a single line (fixed height).

-

16.3.4. Dock area layout

+

15.3.4. Dock area layout

This is a special case. Users cannot choose the dock area layout, but it will be set for the dock area containers. In the dockarea layout (at the moment!), windows will be placed above each other.

-

16.4. Rendering a window

+

15.4. Rendering a window

A window’s size and position will be determined in the following way:

  1. @@ -909,7 +879,7 @@

    16.4. Rendering a window

-

17. Pushing updates to X11 / Drawing

+

16. Pushing updates to X11 / Drawing

A big problem with i3 before version 4 was that we just sent requests to X11 anywhere in the source code. This was bad because nobody could understand the @@ -939,7 +909,7 @@

17. Pushing updates to X11 / Drawing

-

17.1. Pushing state to X11

+

16.1. Pushing state to X11

In general, the function x_push_changes should be called to push state changes. Only when the scope of the state change is clearly defined (for example only the title of a window) and its impact is known beforehand, one can @@ -1049,7 +1019,7 @@

17.1. Pushing state to X11

WM_STATE_WITHDRAWN.

-

17.2. Drawing window decorations/borders/backgrounds

+

16.2. Drawing window decorations/borders/backgrounds

x_draw_decoration draws window decorations. It is run for every leaf container (representing an actual X11 window) and for every non-leaf container which is in a stacked/tabbed container (because stacked/tabbed containers @@ -1068,7 +1038,7 @@

17.2. Drawing window de

-

18. User commands (parser-specs/commands.spec)

+

17. User commands (parser-specs/commands.spec)

In the configuration file and when using i3 interactively (with i3-msg, for example), you use commands to make i3 do things, like focus a different window, @@ -1110,7 +1080,7 @@

18. User commands (parser-spe in which the parser will transition into, or the keyword call, followed by the name of a function (and optionally a state).

-

18.1. Example: The WORKSPACE state

+

17.1. Example: The WORKSPACE state

Let’s have a look at the WORKSPACE state, which is a good example of all features. This is its definition:

@@ -1208,7 +1178,7 @@

18.1. Example: The WORKSPACE state

-

18.2. Introducing a new command

+

17.2. Introducing a new command

The following steps have to be taken in order to properly introduce a new command (or possibly extend an existing command):

    @@ -1254,12 +1224,12 @@

    18.2. Introducing a new command

-

19. Moving containers

+

18. Moving containers

The movement code is pretty delicate. You need to consider all cases before making any changes or before being able to fully understand how it works.

-

19.1. Case 1: Moving inside the same container

+

18.1. Case 1: Moving inside the same container

The reference layout for this case is a single workspace in horizontal orientation with two containers on it. Focus is on the left container (1).

@@ -1284,7 +1254,7 @@

19.1. Case 1: Moving inside th of the current one and swaps both containers.

-

19.2. Case 2: Move a container into a split container

+

18.2. Case 2: Move a container into a split container

The reference layout for this case is a horizontal workspace with two containers. The right container is a v-split with two containers. Focus is on the left container (1).

@@ -1318,7 +1288,7 @@

19.2. Case 2: Move a co be flattened.

-

19.3. Case 3: Moving to non-existent top/bottom

+

18.3. Case 3: Moving to non-existent top/bottom

Like in case 1, the reference layout for this case is a single workspace in horizontal orientation with two containers on it. Focus is on the left container:

@@ -1352,7 +1322,7 @@

19.3. Case 3: Moving to non-e flattened.

-

19.4. Case 4: Moving to existent top/bottom

+

18.4. Case 4: Moving to existent top/bottom

The reference layout for this case is a vertical workspace with two containers. The bottom one is a h-split containing two containers (1 and 2). Focus is on the bottom left container (1).

@@ -1379,7 +1349,7 @@

19.4. Case 4: Moving to existent is in vertical orientation.

-

19.5. Case 5: Moving in one-child h-split

+

18.5. Case 5: Moving in one-child h-split

The reference layout for this case is a horizontal workspace with two containers having a v-split on the left side with a one-child h-split on the bottom. Focus is on the bottom left container (2(h)):

@@ -1411,7 +1381,7 @@

19.5. Case 5: Moving in one-child h 4.

-

19.6. Case 6: Floating containers

+

18.6. Case 6: Floating containers

The reference layout for this case is a horizontal workspace with two containers plus one floating h-split container. Focus is on the floating container.

@@ -1423,7 +1393,7 @@

19.6. Case 6: Floating containers

-

20. Click handling

+

19. Click handling

Without much ado, here is the list of cases which need to be considered:

    @@ -1473,7 +1443,7 @@

    20. Click handling

-

21. Gotchas

+

20. Gotchas

  • @@ -1495,7 +1465,7 @@

    21. Gotchas

-

22. Thought experiments

+

21. Thought experiments

In this section, we collect thought experiments, so that we don’t forget our thoughts about specific topics. They are not necessary to get into hacking i3, @@ -1503,7 +1473,7 @@

22. Thought experiments

before asking us why things are the way they are or why we don’t implement things.

-

22.1. Using cgroups per workspace

+

21.1. Using cgroups per workspace

cgroups (control groups) are a linux-only feature which provides the ability to group multiple processes. For each group, you can individually set resource limits, like allowed memory usage. Furthermore, and more importantly for our