X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3.github.io;a=blobdiff_plain;f=docs%2F4.14%2Fhacking-howto.html;h=a55a82d2b46c3766d394ae15564d5e3745fb1d52;hp=606fad646b1c4ae78fcb674757606e8a873f2e23;hb=755f01b11a32f4185740e1c11a1637cc920a64b5;hpb=15bf0eceb1d9a9bb7b35d4417b378dd0287d1d70 diff --git a/docs/4.14/hacking-howto.html b/docs/4.14/hacking-howto.html index 606fad6..a55a82d 100644 --- a/docs/4.14/hacking-howto.html +++ b/docs/4.14/hacking-howto.html @@ -47,7 +47,111 @@ you find necessary, please do not hesitate to contact me.

-

1. Window Managers

+

1. Building i3

+
+

You can build i3 like you build any other software package which uses autotools. +Here’s a memory refresher:

+
+
+
$ autoreconf -fi
+$ mkdir -p build && cd build
+$ ../configure
+$ make -j8
+
+

(The autoreconf -fi step is unnecessary if you are building from a release tarball, + but shouldn’t hurt either.)

+
+

1.1. 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. +

    +
  • +
  • +

    +“make check” runs the i3 testsuite. See docs/testsuite for details. +

    +
  • +
  • +

    +“make distcheck” (runs testsuite on “make dist” result, tiny bit quicker + feedback cycle than waiting for the travis build to catch the issue). +

    +
  • +
  • +

    +“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. +

    +
  • +
  • +

    +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. +

    +
  • +
  • +

    +Support for pre-compiled headers (PCH) has been dropped for now in the + interest of simplicity. If you need support for PCH, please open an issue. +

    +
  • +
  • +

    +Coverage reports are now generated using “make check-code-coverage”, which + requires specifying --enable-code-coverage when calling configure. +

    +
  • +
+
+
+
+
+

2. Using git / sending patches

+
+ +

Please talk to us before working on new features to see whether they will be +accepted. A good way for this is to open an issue and asking for opinions on it. +Even for accepted features, this can be a good way to refine an idea upfront. However, +we don’t want to see certain features in i3, e.g., switching window focus in an +Alt+Tab like way.

+

When working on bugfixes, please make sure you mention that you are working on +it in the corresponding bug report at https://github.com/i3/i3/issues. In case +there is no bug report yet, please create one.

+

After you are done, please submit your work for review as a pull request at +https://github.com/i3/i3.

+

Do not send emails to the mailing list or any author directly, and don’t submit +them in the bugtracker, since all reviews should be done in public at +https://github.com/i3/i3. In order to make your review go as fast as possible, you +could have a look at previous reviews and see what the common mistakes are.

+
+

2.1. Which branch to use?

+

Work on i3 generally happens in two branches: “master” and “next” (the latter +being the default branch, the one that people get when they check out the git +repository).

+

The contents of “master” are always stable. That is, it contains the source code +of the latest release, plus any bugfixes that were applied since that release.

+

New features are only found in the “next” branch. Therefore, if you are working +on a new feature, use the “next” branch. If you are working on a bugfix, use the +“next” branch, too, but make sure your code also works on “master”.

+
+
+
+
+

3. Window Managers

A window manager is not necessarily needed to run X, but it is usually used in combination with X to facilitate some things. The window manager’s job is to @@ -124,7 +228,7 @@ React to the user’s commands: Change focus, Move windows, Switch workspaces,

In the following chapters, each of these tasks and their implementation details will be discussed.

-

1.1. Tiling window managers

+

3.1. Tiling window managers

Traditionally, there are two approaches to managing windows: The most common one nowadays is floating, which means the user can freely move/resize the windows. The other approach is called tiling, which means that your window @@ -143,7 +247,7 @@ layout (like dwm, awesome, …) but provide mechanisms for you to easily create the layout you need at the moment.

-

1.2. The layout tree

+

3.2. The layout tree

The data structure which i3 uses to keep track of your windows is a tree. Every node in the tree is a container (type Con). Some containers represent actual windows (every container with a window != NULL), some represent split @@ -154,13 +258,13 @@ the same split container, which uses the default layout. In case of an empty workspace, the split container we are talking about is the workspace.

To get an impression of how different layouts are represented, just play around and look at the data structures — they are exposed as a JSON hash. See -http://i3wm.org/docs/ipc.html#_tree_reply for documentation on that and an +https://i3wm.org/docs/ipc.html#_tree_reply for documentation on that and an example.

-

2. Files

+

4. Files

@@ -449,7 +553,7 @@ Legacy support for Xinerama. See src/randr.c for the preferred API.
-

3. Data structures

+

5. Data structures

See include/data.h for documented data structures. The most important ones are explained right here.

@@ -488,14 +592,14 @@ explained right here.

The data type is Con, in all cases.

-

3.1. X11 root window

+

5.1. X11 root window

The X11 root window is a single window per X11 display (a display is identified by :0 or :1 etc.). The root window is what you draw your background image on. It spans all the available outputs, e.g. VGA1 is a specific part of the root window and LVDS1 is a specific part of the root window.

-

3.2. Output container

+

5.2. Output container

Every active output obtained through RandR is represented by one output container. Outputs are considered active when a mode is configured (meaning something is actually displayed on the output) and the output is not a clone.

@@ -510,13 +614,13 @@ workspace will be assigned. New workspaces are created on the output you are currently on.

-

3.3. Content container

+

5.3. Content container

Each output has multiple children. Two of them are dock containers which hold dock clients. The other one is the content container, which holds the actual content (workspaces) of this output.

-

3.4. Workspace

+

5.4. Workspace

A workspace is identified by its name. Basically, you could think of workspaces as different desks in your office, if you like the desktop metaphor. They just contain different sets of windows and are completely @@ -524,7 +628,7 @@ separate of each other. Other window managers also call this “Virtual desktops”.

-

3.5. Split container

+

5.5. Split container

A split container is a container which holds an arbitrary amount of split containers or X11 window containers. It has an orientation (horizontal or vertical) and a layout.

@@ -532,14 +636,14 @@ vertical) and a layout.

containers) can have different border styles.

-

3.6. X11 window container

+

5.6. X11 window container

An X11 window container holds exactly one X11 window. These are the leaf nodes of the layout tree, they cannot have any children.

-

4. List/queue macros

+

6. List/queue macros

i3 makes heavy use of the list macros defined in BSD operating systems. To ensure that the operating system on which i3 is compiled has all the expected @@ -554,7 +658,7 @@ selected window to the window above/below.

-

5. Naming conventions

+

7. Naming conventions

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

@@ -583,7 +687,7 @@ should be chosen for those:

-

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

+

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

  • @@ -620,10 +724,10 @@ Enter the event loop
-

7. Keybindings

+

9. Keybindings

-

7.1. Grabbing the bindings

+

9.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 @@ -644,7 +748,7 @@ check on each press of "a" if the Mode_switch bit is set using XKB. If yes, it will handle the event, if not, it will replay the event.

-

7.2. Handling a keypress

+

9.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 @@ -655,7 +759,7 @@ event.

-

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

+

10. 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:

@@ -691,7 +795,7 @@ target workspace is not visible, the window will not be mapped.

-

9. What happens when an application is started?

+

11. 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 @@ -711,7 +815,7 @@ can reconfigure themselves).

-

10. _NET_WM_STATE

+

12. _NET_WM_STATE

Only the _NET_WM_STATE_FULLSCREEN and _NET_WM_STATE_DEMANDS_ATTENTION atoms are handled.

@@ -722,7 +826,7 @@ Also, it is set as fullscreen_client for the i3Screen.

-

11. WM_NAME

+

13. 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 @@ -731,7 +835,7 @@ if present.

-

12. _NET_WM_NAME

+

14. _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 @@ -740,7 +844,7 @@ characters (every special character contained in your font).

-

13. Size hints

+

15. 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 @@ -753,7 +857,7 @@ src/layout.c, function resize_client().

-

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

+

16. 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 @@ -773,7 +877,7 @@ container and then pushing the changes to X11. The following sections talk about the different rendering steps, in the order of "top of the tree" (root container) to the bottom.

-

14.1. Rendering the root container

+

16.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.

@@ -789,7 +893,7 @@ spanning all outputs), a shortcut is taken and x_raise_con(); render_con()
-

14.2. Rendering an output

+

16.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 @@ -836,20 +940,20 @@ Recursively raise and render the output’s child containers (meaning dock

-

14.3. Rendering a workspace or split container

+

16.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.

-

14.3.1. Default layout

+

16.3.1. Default layout

In default layout, containers are placed horizontally or vertically next to each other (depending on the con->orientation). If a child is a leaf node (as opposed to a split container) and has border style "normal", appropriate space will be reserved for its window decoration.

-

14.3.2. Stacked layout

+

16.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 @@ -860,20 +964,20 @@ reserved (or displayed later on), unless there is more than one window inside the stacked container.

-

14.3.3. Tabbed layout

+

16.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).

-

14.3.4. Dock area layout

+

16.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.

-

14.4. Rendering a window

+

16.4. Rendering a window

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

  1. @@ -902,7 +1006,7 @@ Obey the height- and width-increments of the window (think terminal emulator
-

15. Pushing updates to X11 / Drawing

+

17. 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 @@ -932,7 +1036,7 @@ Expose event handling (drawing decorations): x_deco_recurse() and

-

15.1. Pushing state to X11

+

17.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 @@ -1042,7 +1146,7 @@ unmapped if it should not be visible anymore. WM_STATE will be set to WM_STATE_WITHDRAWN.

-

15.2. Drawing window decorations/borders/backgrounds

+

17.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 @@ -1061,7 +1165,7 @@ and "1pixel") and the top bar (in case of border style "normal").

-

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

+

18. 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, @@ -1103,7 +1207,7 @@ which will be compared with the input. An action is either the name of a state in which the parser will transition into, or the keyword call, followed by the name of a function (and optionally a state).

-

16.1. Example: The WORKSPACE state

+

18.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:

@@ -1201,7 +1305,7 @@ workspace number <number>
-

16.2. Introducing a new command

+

18.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):

    @@ -1247,12 +1351,12 @@ Document the feature in the User’s Guide.
-

17. Moving containers

+

19. 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.

-

17.1. Case 1: Moving inside the same container

+

19.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).

@@ -1277,7 +1381,7 @@ commented with "the easy case": it calls TAILQ_NEXT to get the container right of the current one and swaps both containers.

-

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

+

19.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).

@@ -1311,7 +1415,7 @@ empty.

be flattened.

-

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

+

19.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:

@@ -1345,7 +1449,7 @@ container and the container above/below the current one (on the level of flattened.

-

17.4. Case 4: Moving to existent top/bottom

+

19.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).

@@ -1372,7 +1476,7 @@ orientation change does not need to be performed because the workspace already is in vertical orientation.

-

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

+

19.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)):

@@ -1404,7 +1508,7 @@ orientation will be force-changed), this case is equivalent to case 2 or case 4.

-

17.6. Case 6: Floating containers

+

19.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.

@@ -1416,7 +1520,7 @@ by calling the function attach_to_workspace.

-

18. Click handling

+

20. Click handling

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

    @@ -1466,7 +1570,7 @@ click on border/decoration to resize a tiling con
-

19. Gotchas

+

21. Gotchas

  • @@ -1488,112 +1592,7 @@ Forgetting to call floating_fix_coordinates(con, old_rect, new_rect) af
-

20. Using git / sending patches

-
-
-

20.1. Introduction

-

For a short introduction into using git, see -http://web.archive.org/web/20121024222556/http://www.spheredev.org/wiki/Git_for_the_lazy -or, for more documentation, see http://git-scm.com/documentation

-

Please talk to us before working on new features to see whether they will be -accepted. A good way for this is to open an issue and asking for opinions on it. -Even for accepted features, this can be a good way to refine an idea upfront. However, -we don’t want to see certain features in i3, e.g., switching window focus in an -Alt+Tab like way.

-

When working on bugfixes, please make sure you mention that you are working on -it in the corresponding bug report at https://github.com/i3/i3/issues. In case -there is no bug report yet, please create one.

-

After you are done, please submit your work for review as a pull request at -https://github.com/i3/i3.

-

Do not send emails to the mailing list or any author directly, and don’t submit -them in the bugtracker, since all reviews should be done in public at -https://github.com/i3/i3. In order to make your review go as fast as possible, you -could have a look at previous reviews and see what the common mistakes are.

-
-
-

20.2. Which branch to use?

-

Work on i3 generally happens in two branches: “master” and “next” (the latter -being the default branch, the one that people get when they check out the git -repository).

-

The contents of “master” are always stable. That is, it contains the source code -of the latest release, plus any bugfixes that were applied since that release.

-

New features are only found in the “next” branch. Therefore, if you are working -on a new feature, use the “next” branch. If you are working on a bugfix, use the -“next” branch, too, but make sure your code also works on “master”.

-
-
-

20.3. How to build?

-

You can build i3 like you build any other software package which uses autotools. -Here’s a memory refresher:

-
-
-
$ autoreconf -fi
-$ mkdir -p build && cd build
-$ ../configure
-$ make -j8
-
-

(The autoreconf -fi step is unnecessary if you are building from a release tarball, - but shouldn’t hurt either.)

-
-

20.3.1. 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. -

    -
  • -
  • -

    -“make check” runs the i3 testsuite. See docs/testsuite for details. -

    -
  • -
  • -

    -“make distcheck” (runs testsuite on “make dist” result, tiny bit quicker - feedback cycle than waiting for the travis build to catch the issue). -

    -
  • -
  • -

    -“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. -

    -
  • -
  • -

    -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. -

    -
  • -
  • -

    -Support for pre-compiled headers (PCH) has been dropped for now in the - interest of simplicity. If you need support for PCH, please open an issue. -

    -
  • -
  • -

    -Coverage reports are now generated using “make check-code-coverage”, which - requires specifying --enable-code-coverage when calling configure. -

    -
  • -
-
-
-
-
-
-

21. Thought experiments

+

22. 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, @@ -1601,7 +1600,7 @@ but if you are interested in one of the topics they cover, you should read them before asking us why things are the way they are or why we don’t implement things.

-

21.1. Using cgroups per workspace

+

22.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