static int headless_compositor_create_output(struct headless_compositor *c, struct headless_parameters *param) { struct headless_output *output; struct wl_event_loop *loop; output = zalloc(sizeof *output); if (output == NULL) return -1; output->mode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; output->mode.width = param->width; output->mode.height = param->height; output->mode.refresh = 60000; wl_list_init(&output->base.mode_list); wl_list_insert(&output->base.mode_list, &output->mode.link); output->base.current_mode = &output->mode; weston_output_init(&output->base, &c->base, 0, 0, param->width, param->height, param->transform, 1); output->base.make = "weston"; output->base.model = "headless"; loop = wl_display_get_event_loop(c->base.wl_display); output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output); output->base.start_repaint_loop = headless_output_start_repaint_loop; output->base.repaint = headless_output_repaint; output->base.destroy = headless_output_destroy; output->base.assign_planes = NULL; output->base.set_backlight = NULL; output->base.set_dpms = NULL; output->base.switch_mode = NULL; if (c->use_pixman) { output->image_buf = malloc(param->width * param->height * 4); if (!output->image_buf) return -1; output->image = pixman_image_create_bits(PIXMAN_x8r8g8b8, param->width, param->height, output->image_buf, param->width * 4); if (pixman_renderer_output_create(&output->base) < 0) return -1; pixman_renderer_output_set_buffer(&output->base, output->image); } wl_list_insert(c->base.output_list.prev, &output->base.link); return 0; }
WL_EXPORT int module_init(struct weston_compositor *compositor, int *argc, char *argv[]) { char *watchdog_time_env; struct wl_event_loop *loop; long watchdog_time_conv; struct systemd_notifier *notifier; notifier = zalloc(sizeof *notifier); if (notifier == NULL) return -1; notifier->compositor_destroy_listener.notify = weston_compositor_destroy_listener; wl_signal_add(&compositor->destroy_signal, ¬ifier->compositor_destroy_listener); if (add_systemd_sockets(compositor) < 0) return -1; sd_notify(0, "READY=1"); /* 'WATCHDOG_USEC' is environment variable that is set * by systemd to transfer 'WatchdogSec' watchdog timeout * setting from service file.*/ watchdog_time_env = getenv("WATCHDOG_USEC"); if (!watchdog_time_env) return 0; if (!safe_strtoint(watchdog_time_env, &watchdog_time_conv)) return 0; /* Convert 'WATCHDOG_USEC' to milliseconds and notify * systemd every half of that time.*/ watchdog_time_conv /= 1000 * 2; if (watchdog_time_conv <= 0) return 0; notifier->watchdog_time = watchdog_time_conv; loop = wl_display_get_event_loop(compositor->wl_display); notifier->watchdog_source = wl_event_loop_add_timer(loop, watchdog_handler, notifier); wl_event_source_timer_update(notifier->watchdog_source, notifier->watchdog_time); return 0; }
static int headless_compositor_create_output(struct headless_compositor *c, int width, int height) { struct headless_output *output; struct wl_event_loop *loop; output = malloc(sizeof *output); if (output == NULL) return -1; memset(output, 0, sizeof *output); output->mode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; output->mode.width = width; output->mode.height = height; output->mode.refresh = 60; wl_list_init(&output->base.mode_list); wl_list_insert(&output->base.mode_list, &output->mode.link); output->base.current = &output->mode; weston_output_init(&output->base, &c->base, 0, 0, width, height, WL_OUTPUT_TRANSFORM_NORMAL); output->base.make = "weston"; output->base.model = "headless"; weston_output_move(&output->base, 0, 0); loop = wl_display_get_event_loop(c->base.wl_display); output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output); output->base.origin = output->base.current; output->base.repaint = headless_output_repaint; output->base.destroy = headless_output_destroy; output->base.assign_planes = NULL; output->base.set_backlight = NULL; output->base.set_dpms = NULL; output->base.switch_mode = NULL; wl_list_insert(c->base.output_list.prev, &output->base.link); return 0; }
static dbus_bool_t weston_dbus_add_timeout(DBusTimeout *timeout, void *data) { struct wl_event_loop *loop = data; struct wl_event_source *s; int r; s = wl_event_loop_add_timer(loop, weston_dbus_dispatch_timeout, timeout); if (!s) return FALSE; r = weston_dbus_adjust_timeout(timeout, s); if (r < 0) { wl_event_source_remove(s); return FALSE; } dbus_timeout_set_data(timeout, s, NULL); return TRUE; }
unsigned int DBusHandler::Callbacks::addTimeout(DBusTimeout* timeout, void* data) { if(!data) return 0; auto& loop = static_cast<DBusHandler*>(data)->compositor().wlEventLoop(); wl_event_source* source; if(!(source = wl_event_loop_add_timer(&loop, dispatchTimeout, timeout))) { ny::sendWarning("dbusAddTimeout: failed to add wl_event_loop_timer"); return 0; } if(adjustTimeout(timeout, source) < 0) { ny::sendWarning("dbusAddTimeout: failed to adjust timeout"); wl_event_source_remove(source); return 0; } dbus_timeout_set_data(timeout, source, nullptr); return true; }
WLC_API struct wlc_event_source* wlc_event_loop_add_timer(int (*cb)(void *arg), void *arg) { assert(wlc_event_loop()); return (struct wlc_event_source*)wl_event_loop_add_timer(wlc_event_loop(), cb, arg); }