Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Simplify globals implementation by removing destructors
Browse files Browse the repository at this point in the history
Some globals are static and it doesn't make sense to destroy them before
the wl_display. For instance, wl_compositor should be created before the
display is started and shouldn't be destroyed.

For these globals, we can simplify the code by removing the destructor
and stop keeping track of wl_resources (these will be destroyed with the
wl_display by libwayland).
  • Loading branch information
emersion authored and ddevault committed Nov 25, 2019
1 parent bcd5f7d commit 5cde359
Show file tree
Hide file tree
Showing 57 changed files with 206 additions and 836 deletions.
11 changes: 5 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -242,14 +242,12 @@ at least one struct for each interface in the protocol. For instance,
### Globals
Global interfaces generally have public constructors and destructors. Their
struct has a field holding the `wl_global` itself, a list of resources clients
created by binding to the global, a destroy signal and a `wl_display` destroy
listener. Example:
struct has a field holding the `wl_global` itself, a destroy signal and a
`wl_display` destroy listener. Example:
```c
struct wlr_compositor {
struct wl_global *global;
struct wl_list resources;
struct wl_listener display_destroy;
Expand All @@ -262,8 +260,9 @@ struct wlr_compositor {
```

When the destructor is called, it should emit the destroy signal, remove the
display destroy listener, destroy the `wl_global`, destroy all bound resources
and then destroy the struct.
display destroy listener, destroy the `wl_global` and then destroy the struct.
The destructor can assume all clients and resources have been already
destroyed.

### Resources

Expand Down
6 changes: 0 additions & 6 deletions include/wlr/types/wlr_compositor.h
Expand Up @@ -16,16 +16,11 @@ struct wlr_surface;

struct wlr_subcompositor {
struct wl_global *global;
struct wl_list resources;
struct wl_list subsurface_resources;
};

struct wlr_compositor {
struct wl_global *global;
struct wl_list resources;
struct wlr_renderer *renderer;
struct wl_list surface_resources;
struct wl_list region_resources;

struct wlr_subcompositor subcompositor;

Expand All @@ -37,7 +32,6 @@ struct wlr_compositor {
} events;
};

void wlr_compositor_destroy(struct wlr_compositor *wlr_compositor);
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
struct wlr_renderer *renderer);

Expand Down
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_data_control_v1.h
Expand Up @@ -14,7 +14,6 @@

struct wlr_data_control_manager_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
struct wl_list devices; // wlr_data_control_device_v1::link

struct {
Expand All @@ -41,8 +40,6 @@ struct wlr_data_control_device_v1 {

struct wlr_data_control_manager_v1 *wlr_data_control_manager_v1_create(
struct wl_display *display);
void wlr_data_control_manager_v1_destroy(
struct wlr_data_control_manager_v1 *manager);

void wlr_data_control_device_v1_destroy(
struct wlr_data_control_device_v1 *device);
Expand Down
6 changes: 0 additions & 6 deletions include/wlr/types/wlr_data_device.h
Expand Up @@ -23,7 +23,6 @@ extern const struct wlr_touch_grab_interface

struct wlr_data_device_manager {
struct wl_global *global;
struct wl_list resources;
struct wl_list data_sources;

struct wl_listener display_destroy;
Expand Down Expand Up @@ -162,11 +161,6 @@ struct wlr_drag_drop_event {
struct wlr_data_device_manager *wlr_data_device_manager_create(
struct wl_display *display);

/**
* Destroys a wlr_data_device_manager and removes its wl_data_device_manager global.
*/
void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager);

/**
* Requests a selection to be set for the seat. If the request comes from
* a client, then set `client` to be the matching seat client so that this
Expand Down
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_export_dmabuf_v1.h
Expand Up @@ -15,7 +15,6 @@

struct wlr_export_dmabuf_manager_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
struct wl_list frames; // wlr_export_dmabuf_frame_v1::link

struct wl_listener display_destroy;
Expand All @@ -40,7 +39,5 @@ struct wlr_export_dmabuf_frame_v1 {

struct wlr_export_dmabuf_manager_v1 *wlr_export_dmabuf_manager_v1_create(
struct wl_display *display);
void wlr_export_dmabuf_manager_v1_destroy(
struct wlr_export_dmabuf_manager_v1 *manager);

#endif
4 changes: 1 addition & 3 deletions include/wlr/types/wlr_foreign_toplevel_management_v1.h
Expand Up @@ -15,7 +15,7 @@
struct wlr_foreign_toplevel_manager_v1 {
struct wl_event_loop *event_loop;
struct wl_global *global;
struct wl_list resources;
struct wl_list resources; // wl_resource_get_link
struct wl_list toplevels; // wlr_foreign_toplevel_handle_v1::link

struct wl_listener display_destroy;
Expand Down Expand Up @@ -101,8 +101,6 @@ struct wlr_foreign_toplevel_handle_v1_set_rectangle_event {

struct wlr_foreign_toplevel_manager_v1 *wlr_foreign_toplevel_manager_v1_create(
struct wl_display *display);
void wlr_foreign_toplevel_manager_v1_destroy(
struct wlr_foreign_toplevel_manager_v1 *manager);

struct wlr_foreign_toplevel_handle_v1 *wlr_foreign_toplevel_handle_v1_create(
struct wlr_foreign_toplevel_manager_v1 *manager);
Expand Down
2 changes: 0 additions & 2 deletions include/wlr/types/wlr_fullscreen_shell_v1.h
Expand Up @@ -14,7 +14,6 @@

struct wlr_fullscreen_shell_v1 {
struct wl_global *global;
struct wl_list resources;

struct {
struct wl_signal destroy;
Expand All @@ -36,6 +35,5 @@ struct wlr_fullscreen_shell_v1_present_surface_event {

struct wlr_fullscreen_shell_v1 *wlr_fullscreen_shell_v1_create(
struct wl_display *display);
void wlr_fullscreen_shell_v1_destroy(struct wlr_fullscreen_shell_v1 *shell);

#endif
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_gamma_control_v1.h
Expand Up @@ -5,7 +5,6 @@

struct wlr_gamma_control_manager_v1 {
struct wl_global *global;
struct wl_list resources;
struct wl_list controls; // wlr_gamma_control_v1::link

struct wl_listener display_destroy;
Expand All @@ -29,7 +28,5 @@ struct wlr_gamma_control_v1 {

struct wlr_gamma_control_manager_v1 *wlr_gamma_control_manager_v1_create(
struct wl_display *display);
void wlr_gamma_control_manager_v1_destroy(
struct wlr_gamma_control_manager_v1 *manager);

#endif
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_gtk_primary_selection.h
Expand Up @@ -22,7 +22,6 @@
*/
struct wlr_gtk_primary_selection_device_manager {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
struct wl_list devices; // wlr_gtk_primary_selection_device::link

struct wl_listener display_destroy;
Expand Down Expand Up @@ -54,7 +53,5 @@ struct wlr_gtk_primary_selection_device {

struct wlr_gtk_primary_selection_device_manager *
wlr_gtk_primary_selection_device_manager_create(struct wl_display *display);
void wlr_gtk_primary_selection_device_manager_destroy(
struct wlr_gtk_primary_selection_device_manager *manager);

#endif
2 changes: 0 additions & 2 deletions include/wlr/types/wlr_idle.h
Expand Up @@ -60,8 +60,6 @@ struct wlr_idle_timeout {

struct wlr_idle *wlr_idle_create(struct wl_display *display);

void wlr_idle_destroy(struct wlr_idle *idle);

/**
* Send notification to restart all timers for the given seat. Called by
* compositor when there is an user activity event on that seat.
Expand Down
2 changes: 0 additions & 2 deletions include/wlr/types/wlr_idle_inhibit_v1.h
Expand Up @@ -24,7 +24,6 @@
*/

struct wlr_idle_inhibit_manager_v1 {
struct wl_list resources; // wl_resource_get_link
struct wl_list inhibitors; // wlr_idle_inhibit_inhibitor_v1::link
struct wl_global *global;

Expand Down Expand Up @@ -53,6 +52,5 @@ struct wlr_idle_inhibitor_v1 {
};

struct wlr_idle_inhibit_manager_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display);
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_manager_v1 *idle_inhibit);

#endif
2 changes: 0 additions & 2 deletions include/wlr/types/wlr_input_inhibitor.h
Expand Up @@ -28,7 +28,5 @@ struct wlr_input_inhibit_manager {

struct wlr_input_inhibit_manager *wlr_input_inhibit_manager_create(
struct wl_display *display);
void wlr_input_inhibit_manager_destroy(
struct wlr_input_inhibit_manager *manager);

#endif
4 changes: 1 addition & 3 deletions include/wlr/types/wlr_input_method_v2.h
Expand Up @@ -53,7 +53,6 @@ struct wlr_input_method_v2 {

struct wlr_input_method_manager_v2 {
struct wl_global *global;
struct wl_list bound_resources; // struct wl_resource*::link
struct wl_list input_methods; // struct wlr_input_method_v2*::link

struct wl_listener display_destroy;
Expand All @@ -66,8 +65,6 @@ struct wlr_input_method_manager_v2 {

struct wlr_input_method_manager_v2 *wlr_input_method_manager_v2_create(
struct wl_display *display);
void wlr_input_method_manager_v2_destroy(
struct wlr_input_method_manager_v2 *manager);

void wlr_input_method_v2_send_activate(
struct wlr_input_method_v2 *input_method);
Expand All @@ -84,4 +81,5 @@ void wlr_input_method_v2_send_text_change_cause(
void wlr_input_method_v2_send_done(struct wlr_input_method_v2 *input_method);
void wlr_input_method_v2_send_unavailable(
struct wlr_input_method_v2 *input_method);

#endif
2 changes: 0 additions & 2 deletions include/wlr/types/wlr_layer_shell_v1.h
Expand Up @@ -29,7 +29,6 @@
*/
struct wlr_layer_shell_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource
struct wl_list surfaces; // wl_layer_surface

struct wl_listener display_destroy;
Expand Down Expand Up @@ -97,7 +96,6 @@ struct wlr_layer_surface_v1 {
};

struct wlr_layer_shell_v1 *wlr_layer_shell_v1_create(struct wl_display *display);
void wlr_layer_shell_v1_destroy(struct wlr_layer_shell_v1 *layer_shell);

/**
* Notifies the layer surface to configure itself with this width/height. The
Expand Down
5 changes: 0 additions & 5 deletions include/wlr/types/wlr_linux_dmabuf_v1.h
Expand Up @@ -45,7 +45,6 @@ struct wlr_dmabuf_v1_buffer *wlr_dmabuf_v1_buffer_from_params_resource(
struct wlr_linux_dmabuf_v1 {
struct wl_global *global;
struct wlr_renderer *renderer;
struct wl_list resources;

struct {
struct wl_signal destroy;
Expand All @@ -60,10 +59,6 @@ struct wlr_linux_dmabuf_v1 {
*/
struct wlr_linux_dmabuf_v1 *wlr_linux_dmabuf_v1_create(struct wl_display *display,
struct wlr_renderer *renderer);
/**
* Destroy the linux-dmabuf interface
*/
void wlr_linux_dmabuf_v1_destroy(struct wlr_linux_dmabuf_v1 *linux_dmabuf);

/**
* Returns the wlr_linux_dmabuf if the given resource was created
Expand Down
6 changes: 2 additions & 4 deletions include/wlr/types/wlr_pointer_constraints_v1.h
Expand Up @@ -64,8 +64,8 @@ struct wlr_pointer_constraint_v1 {
};

struct wlr_pointer_constraints_v1 {
struct wl_list resources; // wl_resource_get_link
struct wl_global *global;
struct wl_list constraints; // wlr_pointer_constraint_v1::link

struct {
/**
Expand All @@ -76,15 +76,13 @@ struct wlr_pointer_constraints_v1 {
struct wl_signal new_constraint;
} events;

struct wl_list constraints; // wlr_pointer_constraint_v1::link
struct wl_listener display_destroy;

void *data;
};

struct wlr_pointer_constraints_v1 *wlr_pointer_constraints_v1_create(
struct wl_display *display);
void wlr_pointer_constraints_v1_destroy(
struct wlr_pointer_constraints_v1 *pointer_constraints);

struct wlr_pointer_constraint_v1 *
wlr_pointer_constraints_v1_constraint_for_surface(
Expand Down
8 changes: 2 additions & 6 deletions include/wlr/types/wlr_pointer_gestures_v1.h
Expand Up @@ -15,9 +15,8 @@

struct wlr_pointer_gestures_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
struct wl_list swipes; // wl_resource_get_link
struct wl_list pinches; // wl_resource_get_link
struct wl_list swipes; // wl_resource_get_link
struct wl_list pinches; // wl_resource_get_link

struct wl_listener display_destroy;

Expand Down Expand Up @@ -67,7 +66,4 @@ void wlr_pointer_gestures_v1_send_pinch_end(
uint32_t time_msec,
bool cancelled);

void wlr_pointer_gestures_v1_destroy(
struct wlr_pointer_gestures_v1 *pointer_gestures_v1);

#endif
2 changes: 0 additions & 2 deletions include/wlr/types/wlr_presentation_time.h
Expand Up @@ -19,7 +19,6 @@ struct wlr_output_event_present;

struct wlr_presentation {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
struct wl_list feedbacks; // wlr_presentation_feedback::link
clockid_t clock;

Expand Down Expand Up @@ -71,7 +70,6 @@ struct wlr_backend;

struct wlr_presentation *wlr_presentation_create(struct wl_display *display,
struct wlr_backend *backend);
void wlr_presentation_destroy(struct wlr_presentation *presentation);
/**
* Mark the current surface's buffer as sampled.
*
Expand Down
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_primary_selection_v1.h
Expand Up @@ -14,7 +14,6 @@

struct wlr_primary_selection_v1_device_manager {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
struct wl_list devices; // wlr_primary_selection_v1_device::link

struct wl_listener display_destroy;
Expand Down Expand Up @@ -46,7 +45,5 @@ struct wlr_primary_selection_v1_device {

struct wlr_primary_selection_v1_device_manager *
wlr_primary_selection_v1_device_manager_create(struct wl_display *display);
void wlr_primary_selection_v1_device_manager_destroy(
struct wlr_primary_selection_v1_device_manager *manager);

#endif
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_relative_pointer_v1.h
Expand Up @@ -23,7 +23,6 @@
*/
struct wlr_relative_pointer_manager_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link()
struct wl_list relative_pointers; // wlr_relative_pointer_v1::link

struct {
Expand Down Expand Up @@ -60,8 +59,6 @@ struct wlr_relative_pointer_v1 {

struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(
struct wl_display *display);
void wlr_relative_pointer_manager_v1_destroy(
struct wlr_relative_pointer_manager_v1 *manager);

/**
* Send a relative motion event to the seat. Time is given in microseconds
Expand Down
3 changes: 0 additions & 3 deletions include/wlr/types/wlr_screencopy_v1.h
Expand Up @@ -15,7 +15,6 @@

struct wlr_screencopy_manager_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource
struct wl_list frames; // wlr_screencopy_frame_v1::link

struct wl_listener display_destroy;
Expand Down Expand Up @@ -59,7 +58,5 @@ struct wlr_screencopy_frame_v1 {

struct wlr_screencopy_manager_v1 *wlr_screencopy_manager_v1_create(
struct wl_display *display);
void wlr_screencopy_manager_v1_destroy(
struct wlr_screencopy_manager_v1 *screencopy);

#endif
4 changes: 1 addition & 3 deletions include/wlr/types/wlr_server_decoration.h
Expand Up @@ -44,7 +44,7 @@ enum wlr_server_decoration_manager_mode {
*/
struct wlr_server_decoration_manager {
struct wl_global *global;
struct wl_list resources;
struct wl_list resources; // wl_resource_get_link
struct wl_list decorations; // wlr_server_decoration::link

uint32_t default_mode; // enum wlr_server_decoration_manager_mode
Expand Down Expand Up @@ -80,7 +80,5 @@ struct wlr_server_decoration_manager *wlr_server_decoration_manager_create(
struct wl_display *display);
void wlr_server_decoration_manager_set_default_mode(
struct wlr_server_decoration_manager *manager, uint32_t default_mode);
void wlr_server_decoration_manager_destroy(
struct wlr_server_decoration_manager *manager);

#endif
1 change: 0 additions & 1 deletion include/wlr/types/wlr_tablet_v2.h
Expand Up @@ -141,7 +141,6 @@ struct wlr_tablet_v2_tablet_tool *wlr_tablet_tool_create(
struct wlr_tablet_tool *wlr_tool);

struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display);
void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager);

void wlr_send_tablet_v2_tablet_tool_proximity_in(
struct wlr_tablet_v2_tablet_tool *tool,
Expand Down

0 comments on commit 5cde359

Please sign in to comment.