static void cogland_surface_free (CoglandSurface *surface) { CoglandCompositor *compositor = surface->compositor; CoglandFrameCallback *cb, *next; wl_signal_emit (&surface->destroy_signal, &surface->resource); compositor->surfaces = g_list_remove (compositor->surfaces, surface); cogland_buffer_reference (&surface->buffer_ref, NULL); if (surface->texture) cogl_object_unref (surface->texture); if (surface->pending.buffer) wl_list_remove (&surface->pending.buffer_destroy_listener.link); wl_list_for_each_safe (cb, next, &surface->pending.frame_callback_list, link) wl_resource_destroy (cb->resource); g_slice_free (CoglandSurface, surface); cogland_queue_redraw (compositor); }
WL_EXPORT void wl_event_loop_destroy(struct wl_event_loop *loop) { wl_signal_emit(&loop->destroy_signal, loop); wl_event_loop_process_destroy_list(loop); close(loop->epoll_fd); free(loop); }
static void cogland_buffer_destroy_handler (struct wl_listener *listener, void *data) { CoglandBuffer *buffer = wl_container_of (listener, buffer, destroy_listener); wl_signal_emit (&buffer->destroy_signal, buffer); g_slice_free (CoglandBuffer, buffer); }
WLC_API void wlc_terminate(void) { if (!wlc.display) return; wlc_log(WLC_LOG_INFO, "Terminating wlc..."); wl_signal_emit(&wlc.signals.terminate, NULL); }
static void launcher_logind_set_active(struct launcher_logind *wl, bool active) { if (!wl->compositor->session_active == !active) return; wl->compositor->session_active = active; wl_signal_emit(&wl->compositor->session_signal, wl->compositor); }
static void pixman_renderer_destroy(struct weston_compositor *ec) { struct pixman_renderer *pr = get_renderer(ec); wl_signal_emit(&pr->destroy_signal, pr); weston_binding_destroy(pr->debug_binding); free(pr); ec->renderer = NULL; }
static int vt_handler(int signal_number, void *data) { struct weston_launcher *launcher = data; struct weston_compositor *compositor = launcher->compositor; if (compositor->session_active) { compositor->session_active = 0; wl_signal_emit(&compositor->session_signal, compositor); drmDropMaster(launcher->drm_fd); ioctl(launcher->tty, VT_RELDISP, 1); } else { ioctl(launcher->tty, VT_RELDISP, VT_ACKACQ); drmSetMaster(launcher->drm_fd); compositor->session_active = 1; wl_signal_emit(&compositor->session_signal, compositor); } return 1; }
void clayland_seat_free (ClaylandSeat *seat) { pointer_unmap_sprite (seat); clayland_pointer_release (&seat->pointer); clayland_keyboard_release (&seat->keyboard); wl_signal_emit (&seat->destroy_signal, seat); g_slice_free (ClaylandSeat, seat); }
void wlc_view_focus_ptr(struct wlc_view *view) { if (view && (view->type & WLC_BIT_UNMANAGED)) return; if (view) wlc_x11_window_set_active(&view->x11, true); struct wlc_focus_event ev = { .view = view, .type = WLC_FOCUS_EVENT_VIEW }; wl_signal_emit(&wlc_system_signals()->focus, &ev); }
static int weston_launcher_data(int fd, uint32_t mask, void *data) { struct weston_launcher *launcher = data; int len, ret; if (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) { weston_log("launcher socket closed, exiting\n"); /* Normally the weston-launch will reset the tty, but * in this case it died or something, so do it here so * we don't end up with a stuck vt. */ weston_launcher_restore(launcher); exit(-1); } do { len = recv(launcher->fd, &ret, sizeof ret, 0); } while (len < 0 && errno == EINTR); switch (ret) { case WESTON_LAUNCHER_ACTIVATE: launcher->compositor->session_active = 1; wl_signal_emit(&launcher->compositor->session_signal, launcher->compositor); break; case WESTON_LAUNCHER_DEACTIVATE: launcher->compositor->session_active = 0; wl_signal_emit(&launcher->compositor->session_signal, launcher->compositor); break; default: weston_log("unexpected event from weston-launch\n"); break; } return 1; }
void wlc_set_active(bool active) { if (active == wlc.active) return; wlc.active = active; struct wlc_activate_event ev = { .active = active, .vt = 0 }; wl_signal_emit(&wlc.signals.activate, &ev); wlc_log(WLC_LOG_INFO, (wlc.active ? "become active" : "deactive")); } bool wlc_get_active(void) { return wlc.active; } const struct wlc_interface* wlc_interface(void) { return &wlc.interface; } struct wlc_system_signals* wlc_system_signals(void) { return &wlc.signals; } struct wl_event_loop* wlc_event_loop(void) { return wl_display_get_event_loop(wlc.display); } struct wl_display* wlc_display(void) { return wlc.display; } static void compositor_event(struct wl_listener *listener, void *data) { (void)listener, (void)data; // this event is currently only used for knowing when compositor died wl_display_terminate(wlc.display); }
static void destroy_data_source(struct wl_resource *resource) { struct weston_data_source *source = wl_resource_get_user_data(resource); char **p; wl_signal_emit(&source->destroy_signal, source); wl_array_for_each(p, &source->mime_types) free(*p); wl_array_release(&source->mime_types); free(source); }
static void data_device_end_drag_grab(struct wl_seat *seat) { if (seat->drag_surface) { seat->drag_surface = NULL; wl_signal_emit(&seat->drag_icon_signal, NULL); wl_list_remove(&seat->drag_icon_listener.link); } drag_grab_focus(&seat->drag_grab, NULL, wl_fixed_from_int(0), wl_fixed_from_int(0)); wl_pointer_end_grab(seat->pointer); seat->drag_data_source = NULL; seat->drag_client = NULL; }
static void pixman_renderer_repaint_output(struct weston_output *output, pixman_region32_t *output_damage) { struct pixman_output_state *po = get_output_state(output); if (!po->hw_buffer) return; repaint_surfaces(output, output_damage); copy_to_hw_buffer(output, output_damage); pixman_region32_copy(&output->previous_damage, output_damage); wl_signal_emit(&output->frame_signal, output); /* Actual flip should be done by caller */ }
static int udev_event(int fd, uint32_t mask, void *data) { (void)fd, (void)mask; struct udev *udev = data; struct udev_device *device; if (!(device = udev_monitor_receive_device(udev->monitor))) return 0; wlc_log(WLC_LOG_INFO, "udev: got device %s", udev_device_get_sysname(device)); // FIXME: pass correct drm id if (is_hotplug(0, device)) { wlc_log(WLC_LOG_INFO, "udev: hotplug"); struct wlc_output_event ev = { .type = WLC_OUTPUT_EVENT_UPDATE }; wl_signal_emit(&wlc_system_signals()->output, &ev); goto out; }
WL_EXPORT void wl_seat_set_selection(struct wl_seat *seat, struct wl_data_source *source, uint32_t serial) { struct wl_resource *data_device, *offer; struct wl_resource *focus = NULL; if (seat->selection_data_source && seat->selection_serial - serial < UINT32_MAX / 2) return; if (seat->selection_data_source) { seat->selection_data_source->cancel(seat->selection_data_source); wl_list_remove(&seat->selection_data_source_listener.link); seat->selection_data_source = NULL; } seat->selection_data_source = source; seat->selection_serial = serial; if (seat->keyboard) focus = seat->keyboard->focus_resource; if (focus) { data_device = find_resource(&seat->drag_resource_list, focus->client); if (data_device && source) { offer = wl_data_source_send_offer(seat->selection_data_source, data_device); wl_data_device_send_selection(data_device, offer); } else if (data_device) { wl_data_device_send_selection(data_device, NULL); } } wl_signal_emit(&seat->selection_signal, seat); if (source) { seat->selection_data_source_listener.notify = destroy_selection_data_source; wl_signal_add(&source->resource.destroy_signal, &seat->selection_data_source_listener); } }
static void clipboard_source_unref(struct clipboard_source *source) { char **s; source->refcount--; if (source->refcount > 0) return; if (source->event_source) wl_event_source_remove(source->event_source); wl_signal_emit(&source->base.resource.destroy_signal, &source->base.resource); s = source->base.mime_types.data; free(*s); wl_array_release(&source->base.mime_types); wl_array_release(&source->contents); free(source); }
static void destroy_selection_data_source(struct wl_listener *listener, void *data) { struct weston_seat *seat = container_of(listener, struct weston_seat, selection_data_source_listener); struct wl_resource *data_device; struct weston_surface *focus = NULL; seat->selection_data_source = NULL; if (seat->keyboard) focus = seat->keyboard->focus; if (focus && focus->resource) { data_device = wl_resource_find_for_client(&seat->drag_resource_list, wl_resource_get_client(focus->resource)); if (data_device) wl_data_device_send_selection(data_device, NULL); } wl_signal_emit(&seat->selection_signal, seat); }
static void destroy_selection_data_source(struct wl_listener *listener, void *data) { struct wl_seat *seat = container_of(listener, struct wl_seat, selection_data_source_listener); struct wl_resource *data_device; struct wl_resource *focus = NULL; seat->selection_data_source = NULL; if (seat->keyboard) focus = seat->keyboard->focus_resource; if (focus) { data_device = find_resource(&seat->drag_resource_list, focus->client); if (data_device) wl_data_device_send_selection(data_device, NULL); } wl_signal_emit(&seat->selection_signal, seat); }
static void data_device_start_drag(struct wl_client *client, struct wl_resource *resource, struct wl_resource *source_resource, struct wl_resource *origin_resource, struct wl_resource *icon_resource, uint32_t serial) { struct wl_seat *seat = resource->data; /* FIXME: Check that client has implicit grab on the origin * surface that matches the given time. */ /* FIXME: Check that the data source type array isn't empty. */ seat->drag_grab.interface = &drag_grab_interface; seat->drag_client = client; seat->drag_data_source = NULL; if (source_resource) { seat->drag_data_source = source_resource->data; seat->drag_data_source_listener.notify = destroy_data_device_source; wl_signal_add(&source_resource->destroy_signal, &seat->drag_data_source_listener); } if (icon_resource) { seat->drag_surface = icon_resource->data; seat->drag_icon_listener.notify = destroy_data_device_icon; wl_signal_add(&icon_resource->destroy_signal, &seat->drag_icon_listener); wl_signal_emit(&seat->drag_icon_signal, icon_resource); } wl_pointer_set_focus(seat->pointer, NULL, wl_fixed_from_int(0), wl_fixed_from_int(0)); wl_pointer_start_grab(seat->pointer, &seat->drag_grab); }
static int input_event(int fd, uint32_t mask, void *data) { (void)fd, (void)mask; struct input *input = data; if (libinput_dispatch(input->handle) != 0) wlc_log(WLC_LOG_WARN, "Failed to dispatch libinput"); struct libinput_event *event; while ((event = libinput_get_event(input->handle))) { struct libinput *handle = libinput_event_get_context(event); struct libinput_device *device = libinput_event_get_device(event); (void)handle; switch (libinput_event_get_type(event)) { case LIBINPUT_EVENT_DEVICE_ADDED: WLC_INTERFACE_EMIT(input.created, device); break; case LIBINPUT_EVENT_DEVICE_REMOVED: WLC_INTERFACE_EMIT(input.destroyed, device); break; case LIBINPUT_EVENT_POINTER_MOTION: { struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_MOTION; ev.time = libinput_event_pointer_get_time(pev); ev.motion.dx = libinput_event_pointer_get_dx(pev); ev.motion.dy = libinput_event_pointer_get_dy(pev); wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_MOTION_ABSOLUTE; ev.time = libinput_event_pointer_get_time(pev); ev.motion_abs.x = pointer_abs_x; ev.motion_abs.y = pointer_abs_y; ev.motion_abs.internal = pev; wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_POINTER_BUTTON: { struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_BUTTON; ev.time = libinput_event_pointer_get_time(pev); ev.button.code = libinput_event_pointer_get_button(pev); ev.button.state = (enum wl_pointer_button_state)libinput_event_pointer_get_button_state(pev); wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_POINTER_AXIS: { struct libinput_event_pointer *pev = libinput_event_get_pointer_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_SCROLL; ev.time = libinput_event_pointer_get_time(pev); #if LIBINPUT_VERSION_MAJOR == 0 && LIBINPUT_VERSION_MINOR < 8 /* < libinput 0.8.x (at least to 0.6.x) */ const enum wl_pointer_axis axis = libinput_event_pointer_get_axis(pev); ev.scroll.amount[(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)] = libinput_event_pointer_get_axis_value(pev); ev.scroll.axis_bits |= (axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ? WLC_SCROLL_AXIS_HORIZONTAL : WLC_SCROLL_AXIS_VERTICAL); #else /* > libinput 0.8.0 */ if (libinput_event_pointer_has_axis(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { ev.scroll.amount[0] = libinput_event_pointer_get_axis_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); ev.scroll.axis_bits |= WLC_SCROLL_AXIS_VERTICAL; } if (libinput_event_pointer_has_axis(pev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { ev.scroll.amount[1] = libinput_event_pointer_get_axis_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); ev.scroll.axis_bits |= WLC_SCROLL_AXIS_HORIZONTAL; } #endif // We should get other axis information from libinput as well, like source (finger, wheel) (v0.8) wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_KEYBOARD_KEY: { struct libinput_event_keyboard *kev = libinput_event_get_keyboard_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_KEY; ev.time = libinput_event_keyboard_get_time(kev); ev.key.code = libinput_event_keyboard_get_key(kev); ev.key.state = (enum wl_keyboard_key_state)libinput_event_keyboard_get_key_state(kev); ev.device = device; wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_TOUCH_UP: { struct libinput_event_touch *tev = libinput_event_get_touch_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_TOUCH; ev.time = libinput_event_touch_get_time(tev); ev.touch.type = wlc_touch_type_for_libinput_type(libinput_event_get_type(event)); ev.touch.slot = libinput_event_touch_get_seat_slot(tev); wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_MOTION: { struct libinput_event_touch *tev = libinput_event_get_touch_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_TOUCH; ev.time = libinput_event_touch_get_time(tev); ev.touch.type = wlc_touch_type_for_libinput_type(libinput_event_get_type(event)); ev.touch.x = touch_abs_x; ev.touch.y = touch_abs_y; ev.touch.internal = tev; ev.touch.slot = libinput_event_touch_get_seat_slot(tev); wl_signal_emit(&wlc_system_signals()->input, &ev); } break; case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TOUCH_CANCEL: { struct libinput_event_touch *tev = libinput_event_get_touch_event(event); struct wlc_input_event ev = {0}; ev.type = WLC_INPUT_EVENT_TOUCH; ev.time = libinput_event_touch_get_time(tev); ev.touch.type = wlc_touch_type_for_libinput_type(libinput_event_get_type(event)); wl_signal_emit(&wlc_system_signals()->input, &ev); } break; default: break; } libinput_event_destroy(event); } return 0; }