File: output_tracker.h

package info (click to toggle)
wlmaker 0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,696 kB
  • sloc: ansic: 58,587; xml: 1,424; python: 1,400; cpp: 253; yacc: 118; sh: 73; lex: 70; makefile: 8
file content (130 lines) | stat: -rw-r--r-- 3,902 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ========================================================================= */
/**
 * @file output_tracker.h
 *
 * @copyright
 * Copyright (c) 2026 Google LLC and Philipp Kaeser
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __WLMAKER_OUTPUT_TRACKER_H__
#define __WLMAKER_OUTPUT_TRACKER_H__

#include <libbase/libbase.h>

struct wlr_output;
struct wlr_output_layout;

#ifdef __cplusplus
extern "C" {
#endif  // __cplusplus

/** State of the output tracker. */
typedef struct _wlmtk_output_tracker_t wlmtk_output_tracker_t;

/**
 * Called when `wlr_output_ptr` got added to the layout.
 *
 * @param wlr_output_ptr
 * @param ud_ptr The `userdata_ptr` of @ref wlmtk_output_tracker_create.
 *
 * @return NULL for error, or a pointer that will be passed to
 *     @ref wlmtk_output_tracker_output_update_callback_t, respectively to
 *     @ref wlmtk_output_tracker_output_destroy_callback_t.
 */
typedef void *(*wlmtk_output_tracker_output_create_callback_t)(
    struct wlr_output *wlr_output_ptr,
    void *ud_ptr);

/**
 * Called on layout updates, when `wlr_output_ptr` remains in layout.
 *
 * That can happen eg. when resolution or position changes; or when an
 * unrelated output is added or removed.
 *
 * @param wlr_output_ptr
 * @param ud_ptr
 * @param output_ptr
 */
typedef void (*wlmtk_output_tracker_output_update_callback_t)(
    struct wlr_output *wlr_output_ptr,
    void *ud_ptr,
    void *output_ptr);

/**
 * Called when `wlr_output_ptr` got removed from the layout.
 *
 * @param wlr_output_ptr
 * @param ud_ptr
 * @param output_ptr
 */
typedef void (*wlmtk_output_tracker_output_destroy_callback_t)(
    struct wlr_output *wlr_output_ptr,
    void *ud_ptr,
    void *output_ptr);

/**
 * Creates an output tracker.
 *
 * @param wlr_output_layout_ptr
 * @param userdata_ptr        Will be passed to the callbacks below.
 * @param create_fn
 * @param update_fn
 * @param destroy_fn
 *
 * @return A tracker handle, or NULL on error.
 */
wlmtk_output_tracker_t *wlmtk_output_tracker_create(
    struct wlr_output_layout *wlr_output_layout_ptr,
    void *userdata_ptr,
    wlmtk_output_tracker_output_create_callback_t create_fn,
    wlmtk_output_tracker_output_update_callback_t update_fn,
    wlmtk_output_tracker_output_destroy_callback_t destroy_fn);

/**
 * Destroys the output tracker.
 *
 * @ref wlmtk_output_tracker_output_destroy_callback_t will be called for any
 * yet-remaining output.
 *
 * @param tracker_ptr
 */
void wlmtk_output_tracker_destroy(wlmtk_output_tracker_t *tracker_ptr);

/**
 * Returns the "created output" for `wlr_output_ptr`.
 *
 * @param tracker_ptr
 * @param wlr_output_ptr
 *
 * @return Return value of @ref wlmtk_output_tracker_output_create_callback_t
 *     that was called for the value of `wlr_output_ptr`. Or NULL, if
 *     `wlr_output_ptr` is not tracked.
 */
void *wlmtk_output_tracker_get_output(
    wlmtk_output_tracker_t *tracker_ptr,
    struct wlr_output *wlr_output_ptr);

/** Returns @ref wlmtk_output_tracker_t::wlr_output_layout_ptr. */
struct wlr_output_layout *wlmtk_output_tracker_get_layout(
    wlmtk_output_tracker_t *tracker_ptr);

/** Output tracker unit test. */
extern const bs_test_case_t wlmtk_output_tracker_test_cases[];

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  // __WLMAKER_OUTPUT_TRACKER_H__
/* == End of output_tracker.h ============================================== */