> For the complete documentation index, see [llms.txt](https://i58215.gitbook.io/component-sdl2-en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://i58215.gitbook.io/component-sdl2-en/extended-work-with-the-library./window-event-tracking..md).

# Window event tracking

Each window allows you to track events occurring with it (for example, its movement). Each event can have its own callback function. To do this, use the `addEventListener` method, which is exactly the same as the components and has the following form:

```cpp
void addEventListener(const string& action, 
                      function<void(window* sender, Event* e) callback>);
```

Windows can track the following events:

| Action         | Description                                            |
| -------------- | ------------------------------------------------------ |
| `shown`        | Window has been shown                                  |
| `hidden`       | Window has been hidden                                 |
| `exposed`      | Window has been exposed and should be redrawn          |
| `moved`        | Window has been moved to `data1`, `data2`              |
| `resized`      | Window has been resized to `data1`x`data2`             |
| `minimized`    | Window has been minimized                              |
| `maximized`    | Window has been maximized                              |
| `restored`     | Window has been restored to normal size and position   |
| `enter`        | Window has gained mouse focus                          |
| `leave`        | Window has lost mouse focus                            |
| `focus_gained` | Window has gained keyboard focus                       |
| `focus_lost`   | Window has lost keyboard focus                         |
| `close`        | The window manager requests that the window be closed  |
| `take_focus`   | Window is being offered a focus                        |
| `hit_test`     | Window had a hit test that wasn't `SDL_HITTEST_NORMAL` |

`data1` and `data2` are the fields of the `window` structure of the `Event` union (for example, access to the data1 field looks like this: `e->window.data1`).
