swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 51f7496a92e8f32a9f8c1924f0d63723530df540
parent e8a836cf258af9397fd7442259bc2ffd5cb8c48c
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 25 Nov 2013 01:45:14 -0800

Move udev initialization to swc.c

Diffstat:
Mlibswc/compositor.c | 18+++---------------
Mlibswc/compositor.h | 2--
Mlibswc/drm.c | 13++++++-------
Mlibswc/drm.h | 5+----
Mlibswc/private.h | 2++
Mlibswc/seat.c | 12++++++------
Mlibswc/seat.h | 6++----
Mlibswc/swc.c | 21++++++++++++++++-----
8 files changed, 36 insertions(+), 43 deletions(-)

diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -11,7 +11,6 @@ #include <stdlib.h> #include <stdio.h> -#include <libudev.h> static const char default_seat[] = "seat0"; @@ -330,19 +329,11 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, = &swc_compositor_class_implementation; compositor->cursor_class.interface = &swc_cursor_class_implementation; - compositor->udev = udev_new(); - - if (compositor->udev == NULL) - { - printf("could not initialize udev context\n"); - goto error_base; - } - /* TODO: configurable seat */ - if (!swc_seat_initialize(&compositor->seat, compositor->udev, default_seat)) + if (!swc_seat_initialize(&compositor->seat, default_seat)) { printf("could not initialize seat\n"); - goto error_udev; + goto error_base; } swc_seat_add_event_sources(&compositor->seat, event_loop); @@ -351,7 +342,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, &compositor->pointer_listener); /* TODO: configurable seat */ - if (!swc_drm_initialize(&compositor->drm, compositor->udev, default_seat)) + if (!swc_drm_initialize(&compositor->drm, default_seat)) { printf("could not initialize drm\n"); goto error_seat; @@ -419,8 +410,6 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, swc_drm_finish(&compositor->drm); error_seat: swc_seat_finish(&compositor->seat); - error_udev: - udev_unref(compositor->udev); error_base: return false; } @@ -439,7 +428,6 @@ void swc_compositor_finish(struct swc_compositor * compositor) swc_drm_finish(&compositor->drm); swc_seat_finish(&compositor->seat); - udev_unref(compositor->udev); } void swc_compositor_add_globals(struct swc_compositor * compositor, diff --git a/libswc/compositor.h b/libswc/compositor.h @@ -11,8 +11,6 @@ struct swc_compositor { struct wl_display * display; - struct udev * udev; - struct swc_seat seat; struct swc_drm drm; struct swc_renderer renderer; diff --git a/libswc/drm.c b/libswc/drm.c @@ -25,6 +25,7 @@ #include "drm_buffer.h" #include "output.h" #include "event.h" +#include "private.h" #include <stdio.h> #include <stdlib.h> @@ -132,8 +133,7 @@ static const struct wl_drm_interface drm_implementation = { .create_prime_buffer = &create_prime_buffer }; -static struct udev_device * find_primary_drm_device(struct udev * udev, - const char * seat) +static struct udev_device * find_primary_drm_device(const char * seat) { struct udev_enumerate * enumerate; struct udev_list_entry * entry; @@ -143,7 +143,7 @@ static struct udev_device * find_primary_drm_device(struct udev * udev, struct udev_device * pci; struct udev_device * device, * drm_device = NULL; - enumerate = udev_enumerate_new(udev); + enumerate = udev_enumerate_new(swc.udev); udev_enumerate_add_match_subsystem(enumerate, "drm"); udev_enumerate_add_match_sysname(enumerate, "card[0-9]*"); @@ -152,7 +152,7 @@ static struct udev_device * find_primary_drm_device(struct udev * udev, udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(enumerate)) { path = udev_list_entry_get_name(entry); - device = udev_device_new_from_syspath(udev, path); + device = udev_device_new_from_syspath(swc.udev, path); printf("device node path: %s\n", udev_device_get_devnode(device)); @@ -278,15 +278,14 @@ static int handle_data(int fd, uint32_t mask, void * data) return 1; } -bool swc_drm_initialize(struct swc_drm * drm, struct udev * udev, - const char * seat) +bool swc_drm_initialize(struct swc_drm * drm, const char * seat) { const char * sysnum; char * end; wl_signal_init(&drm->event_signal); - struct udev_device * drm_device = find_primary_drm_device(udev, seat); + struct udev_device * drm_device = find_primary_drm_device(seat); if (!drm_device) { diff --git a/libswc/drm.h b/libswc/drm.h @@ -3,7 +3,6 @@ #include <stdbool.h> #include <stdint.h> -#include <libudev.h> #include <wayland-server.h> struct wld_drm_context * context; @@ -34,9 +33,7 @@ struct swc_drm struct wl_signal event_signal; }; -bool swc_drm_initialize(struct swc_drm * drm, struct udev * udev, - const char * seat); - +bool swc_drm_initialize(struct swc_drm * drm, const char * seat); void swc_drm_finish(struct swc_drm * drm); void swc_drm_add_event_sources(struct swc_drm * drm, diff --git a/libswc/private.h b/libswc/private.h @@ -35,6 +35,8 @@ struct swc struct wl_event_loop * event_loop; const struct swc_manager * manager; + struct udev * udev; + struct swc_compositor * compositor; }; diff --git a/libswc/seat.c b/libswc/seat.c @@ -2,6 +2,7 @@ #include "evdev_device.h" #include "util.h" #include "event.h" +#include "private.h" #include <stdlib.h> #include <stdio.h> @@ -180,8 +181,7 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) wl_list_insert(&seat->devices, &device->link); } -bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev, - const char * seat_name) +bool swc_seat_initialize(struct swc_seat * seat, const char * seat_name) { seat->name = strdup(seat_name); seat->capabilities = 0; @@ -221,7 +221,7 @@ bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev, wl_list_init(&seat->resources); wl_signal_init(&seat->destroy_signal); wl_list_init(&seat->devices); - swc_seat_add_devices(seat, udev); + swc_seat_add_devices(seat); return true; @@ -268,14 +268,14 @@ void swc_seat_add_event_sources(struct swc_seat * seat, } } -void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev) +void swc_seat_add_devices(struct swc_seat * seat) { struct udev_enumerate * enumerate; struct udev_list_entry * entry; const char * path; struct udev_device * device; - enumerate = udev_enumerate_new(udev); + enumerate = udev_enumerate_new(swc.udev); udev_enumerate_add_match_subsystem(enumerate, "input"); udev_enumerate_add_match_sysname(enumerate, "event[0-9]*"); @@ -284,7 +284,7 @@ void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev) udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(enumerate)) { path = udev_list_entry_get_name(entry); - device = udev_device_new_from_syspath(udev, path); + device = udev_device_new_from_syspath(swc.udev, path); add_device(seat, device); udev_device_unref(device); } diff --git a/libswc/seat.h b/libswc/seat.h @@ -11,7 +11,6 @@ #include <stdbool.h> #include <wayland-util.h> -struct udev; struct wl_display; struct wl_event_loop; @@ -35,8 +34,7 @@ struct swc_seat struct swc_evdev_device_handler evdev_handler; }; -bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev, - const char * seat_name); +bool swc_seat_initialize(struct swc_seat * seat, const char * seat_name); void swc_seat_finish(struct swc_seat * seat); @@ -45,7 +43,7 @@ void swc_seat_add_globals(struct swc_seat * seat, struct wl_display * display); void swc_seat_add_event_sources(struct swc_seat * seat, struct wl_event_loop * event_loop); -void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev); +void swc_seat_add_devices(struct swc_seat * seat); #endif diff --git a/libswc/swc.c b/libswc/swc.c @@ -28,6 +28,8 @@ #include "shell.h" #include "window.h" +#include <libudev.h> + static struct swc_compositor compositor; struct swc swc = { @@ -50,16 +52,22 @@ bool swc_initialize(struct wl_display * display, swc.event_loop = event_loop ?: wl_display_get_event_loop(display); swc.manager = manager; + if (!(swc.udev = udev_new())) + { + fprintf(stderr, "Could not initialize udev\n"); + goto error0; + } + if (!swc_bindings_initialize()) { fprintf(stderr, "Could not initialize bindings\n"); - goto error0; + goto error1; } if (!swc_compositor_initialize(&compositor, display, swc.event_loop)) { fprintf(stderr, "Could not initialize compositor\n"); - goto error1; + goto error2; } swc_compositor_add_globals(&compositor, display); @@ -67,17 +75,19 @@ bool swc_initialize(struct wl_display * display, if (!swc_shell_initialize()) { fprintf(stderr, "Could not initialize shell\n"); - goto error2; + goto error3; } setup_compositor(); return true; - error2: + error3: swc_compositor_finish(&compositor); - error1: + error2: swc_bindings_finalize(); + error1: + udev_unref(swc.udev); error0: return false; } @@ -88,5 +98,6 @@ void swc_finalize() swc_shell_finalize(); swc_compositor_finish(&compositor); swc_bindings_finalize(); + udev_unref(swc.udev); }