From 62736aaf47064351e876aeabe5b0dfaae8902a8a Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 15 Apr 2016 23:17:46 +0300 Subject: [PATCH] wlc: bump version 0.0.2 Removes deprecated functions. Replaced wlc_init with wlc_init2. --- CMakeLists.txt | 2 +- example/example.c | 4 +- include/wlc/wlc.h | 142 +----------------------------------- src/compositor/compositor.c | 12 --- src/compositor/output.c | 32 -------- src/compositor/output.h | 4 - src/internal.h | 110 ++++++++++++++++++++++++++++ src/session/fd.c | 5 +- src/session/fd.h | 2 +- src/wlc.c | 16 +--- tests/client.h | 4 +- tests/fullscreen.c | 24 ++---- tests/wl-extension.c | 22 ++---- 13 files changed, 135 insertions(+), 244 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d09e101c..c281349c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.1) -PROJECT(wlc VERSION 0.0.1 LANGUAGES C) +PROJECT(wlc VERSION 0.0.2 LANGUAGES C) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${PROJECT_SOURCE_DIR}/CMake") # Subprojects diff --git a/example/example.c b/example/example.c index c39f3a54..ff0fb2b2 100644 --- a/example/example.c +++ b/example/example.c @@ -251,7 +251,7 @@ cb_log(enum wlc_log_type type, const char *str) } int -main(int argc, char *argv[]) +main(void) { wlc_log_set_handler(cb_log); @@ -266,7 +266,7 @@ main(int argc, char *argv[]) wlc_set_pointer_button_cb(pointer_button); wlc_set_pointer_motion_cb(pointer_motion); - if (!wlc_init2()) + if (!wlc_init()) return EXIT_FAILURE; wlc_run(); diff --git a/include/wlc/wlc.h b/include/wlc/wlc.h index 489b76b9..2d5d3c27 100644 --- a/include/wlc/wlc.h +++ b/include/wlc/wlc.h @@ -120,118 +120,6 @@ struct wlc_modifiers { uint32_t leds, mods; }; -/** Interface struct for communicating with wlc. - * Deprecated, don't use directly. Instead use the wlc_set_*_cb functions below. */ -__attribute__((deprecated("deprecated in favor of wlc_set_*_cb functions"))) -struct wlc_interface { - struct { - /** Output was created. Return false if you want to destroy the output. (e.g. failed to allocate data related to view) */ - bool (*created)(wlc_handle output); - - /** Output was destroyed. */ - void (*destroyed)(wlc_handle output); - - /** Output got or lost focus. */ - void (*focus)(wlc_handle output, bool focus); - - /** Output resolution changed. */ - WLC_NONULL void (*resolution)(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to); - - struct { - /** Output context is created. This generally happens on startup and when current tty changes */ - void (*created)(wlc_handle output); - - /** Output context is destroyed */ - void (*destroyed)(wlc_handle output); - } context; - - struct { - /** Pre render hook. */ - void (*pre)(wlc_handle output); - - /** Post render hook. */ - void (*post)(wlc_handle output); - } render; - } output; - - struct { - /** View was created. Return false if you want to destroy the view. (e.g. failed to allocate data related to view) */ - bool (*created)(wlc_handle view); - - /** View was destroyed. */ - void (*destroyed)(wlc_handle view); - - /** View got or lost focus. */ - void (*focus)(wlc_handle view, bool focus); - - /** View was moved to output. */ - void (*move_to_output)(wlc_handle view, wlc_handle from_output, wlc_handle to_output); - - struct { - /** Request to set given geometry for view. Apply using wlc_view_set_geometry to agree. */ - WLC_NONULL void (*geometry)(wlc_handle view, const struct wlc_geometry*); - - /** Request to disable or enable the given state for view. Apply using wlc_view_set_state to agree. */ - void (*state)(wlc_handle view, enum wlc_view_state_bit, bool toggle); - - /** Request to move itself. Start a interactive move to agree. */ - WLC_NONULL void (*move)(wlc_handle view, const struct wlc_point*); - - /** Request to resize itself with the given edges. Start a interactive resize to agree. */ - WLC_NONULL void (*resize)(wlc_handle view, uint32_t edges, const struct wlc_point*); - } request; - - struct { - /** Pre render hook. */ - void (*pre)(wlc_handle view); - - /** Post render hook. */ - void (*post)(wlc_handle view); - } render; - } view; - - struct { - /** Key event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ - WLC_NONULL bool (*key)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint32_t key, enum wlc_key_state); - } keyboard; - - struct { - /** Button event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ - WLC_NONULL bool (*button)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint32_t button, enum wlc_button_state, const struct wlc_point*); - - /** Scroll event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ - WLC_NONULL bool (*scroll)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint8_t axis_bits, double amount[2]); - - /** Motion event was triggered, view handle will be zero if there was no focus. Apply with wlc_pointer_set_position to agree. Return true to prevent sending the event to clients. */ - WLC_NONULL bool (*motion)(wlc_handle view, uint32_t time, const struct wlc_point*); - } pointer; - - struct { - /** Touch event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ - WLC_NONULL bool (*touch)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, enum wlc_touch_type, int32_t slot, const struct wlc_point*); - } touch; - - struct { - /** Compositor is ready to accept clients. */ - void (*ready)(void); - - /** Compositor is about to terminate */ - void (*terminate)(void); - } compositor; - - /** - * Experimental input api. - * libinput isn't abstracted, so no handles given. - */ - struct { - /** Input device was created. Return value does nothing. */ - bool (*created)(struct libinput_device *device); - - /** Input device was destroyed. */ - void (*destroyed)(struct libinput_device *device); - } input; -}; - /** -- Callbacks API */ /** Output was created. Return false if you want to destroy the output. (e.g. failed to allocate data related to view) */ @@ -328,24 +216,10 @@ void wlc_log_set_handler(void (*cb)(enum wlc_log_type type, const char *str)); * * wlc_init's purpose is to initialize and drop privileges as soon as possible. * - * You can pass argc and argv from main(), so wlc can rename the process it forks - * to cleanup crashed parent process and do FD passing (non-logind). - */ -__attribute__((deprecated("will be replaced with wlc_init2 in next release"))) -bool wlc_init(const struct wlc_interface *interface, int argc, char *argv[]); - -/** - * Initialize wlc. Returns false on failure. - * - * Avoid running unverified code before wlc_init as wlc compositor may be run with higher - * privileges on non logind systems where compositor binary needs to be suid. - * - * wlc_init's purpose is to initialize and drop privileges as soon as possible. - * - * Callbacks should be set using wlc_set_*_cb functions before calling wlc_init2, + * Callbacks should be set using wlc_set_*_cb functions before calling wlc_init, * failing to do so will cause any callback the init may trigger to not be called. */ -bool wlc_init2(void); +bool wlc_init(void); /** Terminate wlc. */ void wlc_terminate(void); @@ -406,10 +280,6 @@ uint32_t wlc_output_get_mask(wlc_handle output); /** Set visibility bitmask. */ void wlc_output_set_mask(wlc_handle output, uint32_t mask); -/** Get pixels. If you return true in callback, the rgba data will be not freed. Do this if you don't want to copy the buffer. */ -__attribute__((deprecated("deprecated in favor of wlc_pixels_read"))) -WLC_NONULL void wlc_output_get_pixels(wlc_handle output, bool (*pixels)(const struct wlc_size *size, uint8_t *rgba, void *arg), void *arg); - /** Get views in stack order. Returned array is a direct reference, careful when moving and destroying handles. */ const wlc_handle* wlc_output_get_views(wlc_handle output, size_t *out_memb); @@ -522,14 +392,6 @@ void wlc_pointer_get_position(struct wlc_point *out_position); /** Set current pointer position. */ void wlc_pointer_set_position(const struct wlc_point *position); -/** Get current pointer origin. */ -__attribute__((deprecated("deprecated in favor of wlc_pointer_get_position"))) -void wlc_pointer_get_origin(struct wlc_origin *out_origin); - -/** Set current pointer origin. */ -__attribute__((deprecated("deprecated in favor of wlc_pointer_set_position"))) -void wlc_pointer_set_origin(const struct wlc_origin *new_origin); - #ifdef __cplusplus } #endif diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index bf00a1d7..5b5cd4e3 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -648,18 +648,6 @@ wlc_pointer_set_position(const struct wlc_point *position) _g_compositor->seat.pointer.pos.y = position->y; } -WLC_API void -wlc_pointer_get_origin(struct wlc_point *out_origin) -{ - wlc_pointer_get_position(out_origin); -} - -WLC_API void -wlc_pointer_set_origin(const struct wlc_point *new_origin) -{ - wlc_pointer_set_position(new_origin); -} - void wlc_compositor_terminate(struct wlc_compositor *compositor) { diff --git a/src/compositor/output.c b/src/compositor/output.c index e312178d..4e41679c 100644 --- a/src/compositor/output.c +++ b/src/compositor/output.c @@ -359,18 +359,6 @@ repaint(struct wlc_output *output) rendering_output = NULL; - { - size_t sz; - void *rgba; - struct wlc_geometry g = { { 0, 0 }, output->resolution }; - if (output->task.pixels.cb && !chck_mul_ofsz(g.size.w, g.size.h, &sz) && (rgba = chck_calloc_of(4, sz))) { - wlc_render_read_pixels(&output->render, &output->context, WLC_RGBA8888, &g, &g, rgba); - if (!output->task.pixels.cb(&g.size, rgba, output->task.pixels.arg)) - free(rgba); - memset(&output->task.pixels, 0, sizeof(output->task.pixels)); - } - } - output->state.pending = true; wlc_context_swap(&output->context, &output->bsurface); @@ -826,20 +814,6 @@ wlc_output_set_mask_ptr(struct wlc_output *output, uint32_t mask) wlc_output_schedule_repaint(output); } -void -wlc_output_get_pixels_ptr(struct wlc_output *output, bool (*pixels)(const struct wlc_size *size, uint8_t *rgba, void *arg), void *arg) -{ - assert(pixels); - - if (!output) - return; - - // TODO: we need real task system, not like we do right now. - output->task.pixels.cb = pixels; - output->task.pixels.arg = arg; - wlc_output_schedule_repaint(output); -} - bool wlc_output_set_views_ptr(struct wlc_output *output, const wlc_handle *views, size_t memb) { @@ -926,12 +900,6 @@ wlc_output_set_mask(wlc_handle output, uint32_t mask) wlc_output_set_mask_ptr(convert_from_wlc_handle(output, "output"), mask); } -WLC_API void -wlc_output_get_pixels(wlc_handle output, bool (*pixels)(const struct wlc_size *size, uint8_t *rgba, void *arg), void *arg) -{ - wlc_output_get_pixels_ptr(convert_from_wlc_handle(output, "output"), pixels, arg); -} - WLC_API const wlc_handle* wlc_output_get_views(wlc_handle output, size_t *out_memb) { diff --git a/src/compositor/output.h b/src/compositor/output.h index 0ea93c16..c2525446 100644 --- a/src/compositor/output.h +++ b/src/compositor/output.h @@ -65,10 +65,6 @@ struct wlc_output { // FIXME: replace with better system struct { - struct { - void *arg; - bool (*cb)(const struct wlc_size *size, uint8_t *rgba, void *userdata); - } pixels; struct wlc_backend_surface bsurface; bool terminate; bool sleep; diff --git a/src/internal.h b/src/internal.h index bcc5c9aa..88eb28f9 100644 --- a/src/internal.h +++ b/src/internal.h @@ -15,6 +15,116 @@ # define WLC_LOG_ATTR(x, y) #endif +/* Interface struct for communicating with wlc. */ +struct wlc_interface { + struct { + /** Output was created. Return false if you want to destroy the output. (e.g. failed to allocate data related to view) */ + bool (*created)(wlc_handle output); + + /** Output was destroyed. */ + void (*destroyed)(wlc_handle output); + + /** Output got or lost focus. */ + void (*focus)(wlc_handle output, bool focus); + + /** Output resolution changed. */ + WLC_NONULL void (*resolution)(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to); + + struct { + /** Output context is created. This generally happens on startup and when current tty changes */ + void (*created)(wlc_handle output); + + /** Output context is destroyed */ + void (*destroyed)(wlc_handle output); + } context; + + struct { + /** Pre render hook. */ + void (*pre)(wlc_handle output); + + /** Post render hook. */ + void (*post)(wlc_handle output); + } render; + } output; + + struct { + /** View was created. Return false if you want to destroy the view. (e.g. failed to allocate data related to view) */ + bool (*created)(wlc_handle view); + + /** View was destroyed. */ + void (*destroyed)(wlc_handle view); + + /** View got or lost focus. */ + void (*focus)(wlc_handle view, bool focus); + + /** View was moved to output. */ + void (*move_to_output)(wlc_handle view, wlc_handle from_output, wlc_handle to_output); + + struct { + /** Request to set given geometry for view. Apply using wlc_view_set_geometry to agree. */ + WLC_NONULL void (*geometry)(wlc_handle view, const struct wlc_geometry*); + + /** Request to disable or enable the given state for view. Apply using wlc_view_set_state to agree. */ + void (*state)(wlc_handle view, enum wlc_view_state_bit, bool toggle); + + /** Request to move itself. Start a interactive move to agree. */ + WLC_NONULL void (*move)(wlc_handle view, const struct wlc_point*); + + /** Request to resize itself with the given edges. Start a interactive resize to agree. */ + WLC_NONULL void (*resize)(wlc_handle view, uint32_t edges, const struct wlc_point*); + } request; + + struct { + /** Pre render hook. */ + void (*pre)(wlc_handle view); + + /** Post render hook. */ + void (*post)(wlc_handle view); + } render; + } view; + + struct { + /** Key event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ + WLC_NONULL bool (*key)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint32_t key, enum wlc_key_state); + } keyboard; + + struct { + /** Button event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ + WLC_NONULL bool (*button)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint32_t button, enum wlc_button_state, const struct wlc_point*); + + /** Scroll event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ + WLC_NONULL bool (*scroll)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint8_t axis_bits, double amount[2]); + + /** Motion event was triggered, view handle will be zero if there was no focus. Apply with wlc_pointer_set_position to agree. Return true to prevent sending the event to clients. */ + WLC_NONULL bool (*motion)(wlc_handle view, uint32_t time, const struct wlc_point*); + } pointer; + + struct { + /** Touch event was triggered, view handle will be zero if there was no focus. Return true to prevent sending the event to clients. */ + WLC_NONULL bool (*touch)(wlc_handle view, uint32_t time, const struct wlc_modifiers*, enum wlc_touch_type, int32_t slot, const struct wlc_point*); + } touch; + + struct { + /** Compositor is ready to accept clients. */ + void (*ready)(void); + + /** Compositor is about to terminate */ + void (*terminate)(void); + } compositor; + + /** + * Experimental input api. + * libinput isn't abstracted, so no handles given. + */ + struct { + /** Input device was created. Return value does nothing. */ + bool (*created)(struct libinput_device *device); + + /** Input device was destroyed. */ + void (*destroyed)(struct libinput_device *device); + } input; +}; + enum wlc_connector_type { /* used when running wlc with backend (e.g. x11) that does not use real output. */ WLC_CONNECTOR_WLC, diff --git a/src/session/fd.c b/src/session/fd.c index 4460634c..67344c94 100644 --- a/src/session/fd.c +++ b/src/session/fd.c @@ -522,7 +522,7 @@ wlc_fd_terminate(void) } void -wlc_fd_init(int argc, char *argv[], bool has_logind) +wlc_fd_init(bool has_logind) { wlc.has_logind = has_logind; @@ -545,9 +545,6 @@ wlc_fd_init(int argc, char *argv[], bool has_logind) sigaction(SIGINT, &action, NULL); sigaction(SIGTERM, &action, NULL); - for (int i = 0; i < argc; ++i) - strncpy(argv[i], (i == 0 ? "wlc" : ""), strlen(argv[i])); - communicate(sock[1], getppid()); _exit(EXIT_SUCCESS); } else if (wlc.child < 0) { diff --git a/src/session/fd.h b/src/session/fd.h index cd337da7..7e931d48 100644 --- a/src/session/fd.h +++ b/src/session/fd.h @@ -18,6 +18,6 @@ bool wlc_fd_activate_vt(int vt); WLC_NONULL int wlc_fd_open(const char *path, int flags, enum wlc_fd_type type); void wlc_fd_close(int fd); void wlc_fd_terminate(void); -void wlc_fd_init(int argc, char *argv[], bool has_logind); +void wlc_fd_init(bool has_logind); #endif /* _WLC_FD_H_ */ diff --git a/src/wlc.c b/src/wlc.c index b7309612..2da896c5 100644 --- a/src/wlc.c +++ b/src/wlc.c @@ -279,11 +279,8 @@ wlc_terminate(void) } WLC_API bool -wlc_init(const struct wlc_interface *interface, int argc, char *argv[]) +wlc_init(void) { - if (argc > 0 && !argv) - die("argc was more than 0, but argv was NULL"); - if (wlc.display) return true; @@ -335,7 +332,7 @@ wlc_init(const struct wlc_interface *interface, int argc, char *argv[]) { struct wl_display *display = wlc.display; wlc.display = NULL; - wlc_fd_init(argc, argv, (vt != 0)); + wlc_fd_init((vt != 0)); wlc.display = display; } @@ -380,18 +377,9 @@ wlc_init(const struct wlc_interface *interface, int argc, char *argv[]) if (!wlc_compositor(&wlc.compositor)) die("Failed to init compositor"); - if (interface) - wlc.interface = *interface; - return true; } -WLC_API bool -wlc_init2(void) -{ - return wlc_init(NULL, 0, NULL); -} - WLC_API void wlc_set_output_created_cb(bool (*cb)(wlc_handle output)) { diff --git a/tests/client.h b/tests/client.h index 21b36001..71a065ac 100644 --- a/tests/client.h +++ b/tests/client.h @@ -387,14 +387,14 @@ cb_log(enum wlc_log_type type, const char *str) } static inline void -compositor_test_create(struct compositor_test *test, int argc, char *argv[], const char *name, const struct wlc_interface *interface) +compositor_test_create(struct compositor_test *test, const char *name) { assert(test && name); memset(test, 0, sizeof(struct compositor_test)); test->name = name; wlc_log_set_handler(cb_log); setup_signals(compositor_sigterm); - assert(wlc_init(interface, argc, argv)); + assert(wlc_init()); } static inline void diff --git a/tests/fullscreen.c b/tests/fullscreen.c index febb719e..5b8ade6d 100644 --- a/tests/fullscreen.c +++ b/tests/fullscreen.c @@ -54,28 +54,18 @@ compositor_ready(void) } static int -compositor_main(int argc, char *argv[]) +compositor_main(void) { - static struct wlc_interface interface = { - .view = { - .move_to_output = view_move_to_output, - - .request = { - .state = view_request_state, - }, - }, - - .compositor = { - .ready = compositor_ready, - }, - }; + wlc_set_view_move_to_output_cb(view_move_to_output); + wlc_set_view_request_state_cb(view_request_state); + wlc_set_compositor_ready_cb(compositor_ready); // This causes nouveau to hang at quit. // Comment out until headless backend is added. // setenv("WLC_OUTPUTS", "2", true); view_moved_to_output = true; - compositor_test_create(&compositor, argc, argv, "fullscreen", &interface); + compositor_test_create(&compositor, "fullscreen"); wlc_run(); assert(fullscreen_state_requested); @@ -84,7 +74,7 @@ compositor_main(int argc, char *argv[]) } int -main(int argc, char *argv[]) +main(void) { - return compositor_main(argc, argv); + return compositor_main(); } diff --git a/tests/wl-extension.c b/tests/wl-extension.c index 034c1b94..00e877e1 100644 --- a/tests/wl-extension.c +++ b/tests/wl-extension.c @@ -1,6 +1,7 @@ #include "wayland-test-extension-client-protocol.h" #include "client.h" #include +#include #include "wayland-test-extension-server-protocol.h" static struct compositor_test compositor; @@ -79,21 +80,12 @@ compositor_ready(void) } static int -compositor_main(int argc, char *argv[]) +compositor_main(void) { - static struct wlc_interface interface = { - .output = { - .render = { - .pre = output_render_pre, - }, - }, + wlc_set_output_render_pre_cb(output_render_pre); + wlc_set_compositor_ready_cb(compositor_ready); - .compositor = { - .ready = compositor_ready, - }, - }; - - compositor_test_create(&compositor, argc, argv, "wl-extension", &interface); + compositor_test_create(&compositor, "wl-extension"); if (!wl_global_create(wlc_get_wl_display(), &background_interface, 1, NULL, background_bind)) return EXIT_FAILURE; @@ -104,7 +96,7 @@ compositor_main(int argc, char *argv[]) } int -main(int argc, char *argv[]) +main(void) { - return compositor_main(argc, argv); + return compositor_main(); }